/*
SQLyog Ultimate v11.42 (64 bit)
MySQL - 5.5.24-CDB-2.0.0-log : Database - myblog
*********************************************************************
*/

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`myblog` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `myblog`;

/*Table structure for table `blog_article` */

DROP TABLE IF EXISTS `blog_article`;

CREATE TABLE `blog_article` (
  `id` varchar(24) NOT NULL,
  `title` varchar(50) NOT NULL COMMENT '文章标题',
  `content` longtext NOT NULL COMMENT '文章内容',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `navigation_id` varchar(24) NOT NULL COMMENT '所属类型',
  `user_id` varchar(24) NOT NULL COMMENT '作者id',
  `introduction` varchar(500) DEFAULT NULL COMMENT '简介',
  `available` int(1) DEFAULT '1' COMMENT '是否可用',
  `view_link` varchar(100) DEFAULT NULL COMMENT '视图链接',
  `is_view_open` int(1) NOT NULL DEFAULT '1' COMMENT '是否视图访问，默认否-1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章';

/*Data for the table `blog_article` */

insert  into `blog_article`(`id`,`title`,`content`,`create_time`,`update_time`,`navigation_id`,`user_id`,`introduction`,`available`,`view_link`,`is_view_open`) values ('555d70fa73dc9df5a777610e','Apache + Tomcat集群环境搭建','<p class=\"MsoNormal\"><b><span style=\"font-family:宋体;color:#009900;\"><span style=\"color:#009900;line-height:2;font-size:12px;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\"><span style=\"color:#009900;font-size:12px;line-height:2;\"><strong>参考文章</strong></span></span></span></span></span></span></span><span style=\"line-height:2;font-size:12px;\">：</span></span><span style=\"color:#009900;line-height:2;font-size:12px;\">http://zyycaesar.iteye.com/blog</span></b></p><p class=\"MsoNormal\"><b><span style=\"color:#009900;\"><br></span></b></p><p class=\"MsoNormal\"><span style=\"color:#009900;font-size:14px;\"><strong><span style=\"line-height:2;font-size:12px;\">[</span><span style=\"color:#009900;line-height:2;font-size:12px;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\"><span style=\"color:#009900;font-size:12px;line-height:2;\"><strong>环境说明</strong></span></span></span></span></span></span></span><span style=\"line-height:2;font-size:12px;\">]:</span></strong></span></p><ol><li><span style=\"color:#009900;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">我本地电脑是</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">win7</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">的</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\"> 64</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">位操作系统</span></span></li><li><span style=\"color:#009900;\"><span style=\"font-size:10.5pt;font-family:宋体;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">使用</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">tomcat</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">之前，请安装好</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">jdk</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">环境，并且可以成功访问运行</span></span></span></li><li><span style=\"color:#009900;\"><span style=\"font-size:10.5pt;font-family:宋体;\"><span style=\"font-size:10.5pt;font-family:宋体;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">我使用的是</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">tomcat7</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">，</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">jdk</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">为</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">1.7</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">版本</span></span></span></span></li><li><span style=\"color:#000000;line-height:2;font-size:12px;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">由于版本不一致可能会造成安装或者测试出现问题</span></span></span></span></span></li><li><span style=\"color:#009900;\"><span style=\"font-size:10.5pt;font-family:宋体;\"><span style=\"font-size:10.5pt;font-family:宋体;\"><span style=\"font-size:10.5pt;font-family:宋体;\"><span style=\"font-size:10.5pt;font-family:宋体;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">本教程中安装</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">Apache</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">和</span><span style=\"font-size:12px;font-family:&quot;color:#000000;line-height:2;\">tomcat</span><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\">均工作在同一台机器上</span></span></span></span></span></span></li></ol><p><span style=\"color:#009900;line-height:2;font-size:12px;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;line-height:2;\"><span style=\"font-size:12px;font-family:宋体;color:#000000;line-height:2;\"><span style=\"color:#009900;font-size:12px;line-height:2;\"><strong>[软件准备]</strong></span></span></span></span></span></span></span><b><span style=\"color:#009900;\"><b><span style=\"color:#009900;\"><span><span style=\"font-family:&quot;color:black;background:white;\"></span></span></span></b></span></b></p><ol><li><span style=\"line-height:2;font-size:12px;\">Apache 2.2</span></li><li><span style=\"line-height:2;font-size:12px;\">Tomcat7</span></li></ol><p><span style=\"line-height:2;font-size:12px;color:#009900;\"><strong>[软件安装]</strong></span></p><ol><li><span style=\"color:#EE33EE;\">JDK安装</span></li><li><span style=\"color:#EE33EE;\">Apache安装</span></li></ol><ul><li>打开运行httpd-2.2.25-win32-x86-no_ssl.msi，中途无需配置什么东西，直接下一步进行即可，我安装在D:\\Apache2.2</li><li>安装结束后，进入D:\\Apache2.2\\bin目录下运行httpd.exe启动apache服务</li><li>打开浏览器访问apache是否安装成功http://localhost:80 ，apache默认端口是80</li><li>如果该端口与其他服务端口(如tomcat端口)冲突,则可以手动修改端口，打开D:\\Apache2.2\\conf目录下的httpd.conf文件,搜索找到Listen 80，将80修改成自己需要的端口即可.重新启动apache，<br>再次访问http://localhost:修改的端口号，如果出现下方结果，说明apache安装成功，并且可以访问服务。<br><img src=\"http://zhoubang85.com/resources/attached/image/20150521112315_219.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521112315_219.jpg\" alt=\"\"></li></ul><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 3.<span style=\"color:#EE33EE;\">安装tomcat</span></p><ul><li>本\n事例基于2个tomcat服务器集群，所以解压apache-tomcat-7.0.57-windows-x64.zip文件到两个文件夹，我这里分别\n是D:\\tomcat1和D:\\tomcat2，分别命名为tomcat1和tomcat2配置。先启动tomcat1，确定tomcat1可以正常访\n问，关闭tomcat1，启动tomcat2，确保tomca2t可用，然后关闭tomcat2。</li></ul><p><strong><span style=\"color:#009900;\">[环境搭建]</span></strong></p><ol><li><span style=\"color:#EE33EE;\">Tomcat配置</span></li></ol><ul><li>由于2个tomcat运行在同一台机器上，所以只需要修改其中一个tomcat的配置即可，另一个不用修改，如果是n个tomcat以上（包括n台）集群运行在同一台机器上,，则需要至少修改n-1个tomcat的端口配置。保证它们之间不会冲突。</li><li>这里我们只要修改其中一个即可，这里修改D:\\tomcat2\\conf\\ server.xml的端口号，使用编辑器打开，.分别进行下面的配置：<br>找到&lt;Server port=\"8005\" shutdown=\"SHUTDOWN\"&gt;，在22行,将8005修改为9005。可以自己指定。 <br>然后修改(&lt;Connector port=\"8080\" protocol=\"HTTP/1.1\" ….)，在第71行，默认为8080，这里修改为9080<br>最后再修改(&lt;Connector port=\"8009\" protocol=\"AJP/1.3\" redirectPort=\"8443\" /&gt;)，在第93行，默认为8009，这里修改为9009<br>最后，找到&lt;Engine name=\"Catalina\" defaultHost=\"localhost\"&gt;，添加一个属性jvmRoute ,值为自定义的jvm名称.配置如下：<br><pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Engine name=\"Catalina\" defaultHost=\"localhost\" jvmRoute=\"jvm2\"&gt;<br></code></pre><br>当然，D:\\tomcat1\\conf\\ server.xml中也需要进行修改.命名为jvm1</li><li>Tomcat各项端口修改完毕之后，分别启动这2个tomcat，看看是否启动报错？网页是否成功访问？如果出错，请重新检查配置。<br>[说明]：如果是更多的tomcat之间集群，修改方式同上。</li></ul>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. <span style=\"color:#EE33EE;\">Apache配置</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apache 2.2集成了mod_jk功能，不需要再进行繁琐的worker.properties配置，配置过程大幅简化。如果不知道mod_jk是什么，可以百度搜一下即可明白。<br><ul><li>首先，在Apache安装目录下找到conf/httpd.conf文件，我本地路径为D:\\Apache2.2\\conf\\httpd.conf，以文本编辑器打开，我使用的是Notepad编辑器<br>去掉以下文本前的注释符（#）以便让Apache在启动时自动加载代理（proxy）模块。<br><pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp; #LoadModule proxy_module modules/mod_proxy.so<br>&nbsp;&nbsp;&nbsp;&nbsp; #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so<br>&nbsp;&nbsp;&nbsp;&nbsp; #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so<br>&nbsp;&nbsp;&nbsp;&nbsp; #LoadModule proxy_connect_module modules/mod_proxy_connect.so<br>&nbsp;&nbsp;&nbsp;&nbsp; #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so<br>&nbsp;&nbsp;&nbsp;&nbsp; #LoadModule proxy_http_module modules/mod_proxy_http.so<br></code></pre><br><span id=\"__kindeditor_bookmark_start_434__\"></span>配置结果如下:<br><img src=\"http://zhoubang85.com/resources/attached/image/20150521125709_183.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521125709_183.jpg\" alt=\"\"></li><li>然后再搜索找到&lt;IfModule dir_module&gt;节点(大概在241行)，在DirectoryIndex index.html后加上index.jsp，注意中间的空格，这一步只是为了待会配置完tomcat后能看到小猫首页，这一步可以不做.</li><li>继续再搜索找到Include conf/extra/httpd-vhosts.conf(大概在471行)，去掉前面的注释符。</li><li>用文本编辑器打开D:\\Apache2.2\\conf\\extra\\httpd-vhosts.conf，配置虚拟站点，在最下面加上:<br><pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;VirtualHost *:80&gt;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerAdmin 管理员邮箱<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ServerName 域名（没有可用IP地址代替）<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ServerAlias localhost <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ProxyPassReverse / balancer://cluster/ <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ErrorLog \"logs/zb-error.log\"<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;CustomLog \"logs/zb-access.log\" common<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/VirtualHost&gt;<br></code></pre><br><br>我这里最终的配置如下:<br><pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;VirtualHost *:80&gt;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerAdmin 842324724@qq.com<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ServerName 127.0.0.1<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ServerAlias localhost <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProxyPassReverse / balancer://cluster/ <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ErrorLog \"logs/zb-error.log\"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomLog \"logs/zb-access.log\" common<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/VirtualHost&gt;<br></code></pre><br><p class=\"MsoNormal\" style=\"text-align:left;\" align=\"left\"><span style=\"font-family:宋体;color:black;background:white;\">上面配置信息中的</span><span style=\"font-family:&quot;color:red;background:white;\">balancer://</span><span style=\"font-family:宋体;color:black;background:white;\">是告诉</span><span style=\"font-family:&quot;color:black;background:white;\">Apache</span><span style=\"font-family:宋体;color:black;background:white;\">需要进行负载均衡的代理，后面的</span><span style=\"font-family:&quot;color:#0070C0;background:white;\">cluster</span><span style=\"font-family:宋体;color:black;background:white;\">是</span><b><span style=\"font-family:宋体;color:#C00000;background:white;\">集群名</span></b><span style=\"font-family:宋体;color:black;background:white;\">，可以随意取，两个日志引擎</span><span style=\"font-family:&quot;color:#00B050;background:white;\">ErrorLog</span><span style=\"font-family:宋体;color:black;background:white;\">负责记录错误，</span><span style=\"font-family:&quot;color:#00B050;background:white;\">CustomLog</span><span style=\"font-family:宋体;color:black;background:white;\">负责记录所有的</span><span style=\"font-family:&quot;color:black;background:white;\">http</span><span style=\"font-family:宋体;color:black;background:white;\">访问以及返回状态，日志名可以自己取，这里取为</span><span style=\"font-family:&quot;color:red;background:white;\">zb，</span><span style=\"font-family:宋体;color:red;background:white;\"></span><span style=\"font-family:宋体;color:black;background:white;\">这些日志文件不需要自己创建，访问</span><span style=\"font-family:&quot;color:black;background:white;\">apache</span><span style=\"font-family:宋体;color:black;background:white;\">服务的时候会自行创建</span><span style=\"font-family:&quot;color:black;background:white;\">.</span></p></li><li><span style=\"font-family:&quot;color:black;background:white;\">httpd-vhosts.conf配置完毕之后，打开apache的httpd.conf文件，在文档最下面加上:<br><pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp;ProxyRequests Off <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;proxy balancer://cluster&gt; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;BalancerMember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;BalancerMember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/proxy&gt;<br></code></pre><br>ProxyRequests Off 是告诉Apache需要使用反向代理，&lt;proxy balancer://cluster&gt;用于配置工作在tomcat集群中的所有节点，这里的\"cluster\"必须与上面的集群名保持一致。<br>Apache通过ajp协议与tomcat进行通信，ip地址和端口唯一确定了tomcat节点和配置的ajp接受端口。<br>上面的8009和9009分别对应着2个tomcat的conf目录下的server.xml文件中的第93行的ajp端口，如下：<br><pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Connector port=\"8009\" protocol=\"AJP/1.3\" redirectPort=\"8443\" /&gt;<br></code></pre><br>loadfactor是负载因子，Apache会按负载因子的比例向后端tomcat节点转发请求，负载因子越大，对应的tomcat服务器就会处理越多的请求，如两个tomcat都是1，Apache就按1：1的比例转发，如果是2和1就按2：1的比例转发。<br>route参数对应之前上面tomcat配置中的引擎路径（jvmRoute）。<br><br></span></li></ul><span style=\"font-family:&quot;color:black;background:white;\"></span><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重启Apache服务，如果此时访问http://localhost/将会返回503错误，打开刚才配置的错误日志D:\\Apache2.2\\logs\\zb-error.log，里面会出现这样的信息：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://zhoubang85.com/resources/attached/image/20150521130443_498.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521130443_498.jpg\" alt=\"\"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;可以看到错误原因是因为2个tomcat服务器没有响应，因为此时tomcat没有启动,启动这2个tomcat.再次测试访问.此时2个tomcat的webapps目录下并没有加入自己的测试项目，<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所以，通过浏览器访问http://localhost/的时候，页面会显示tomcat的默认页面.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这里需要注意，其实访问的过程中已经是集群分发访问了。如果你修改2个tomcat的webapps下的ROOT中的index.jsp的内容，之后再不停的访问http://localhost，<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;你会发现，网页所展示的内容，分别是tomcat1和tomcat2的默认页面. 依次循环显示。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;下面就是访问http://localhost之后的结果对比：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://zhoubang85.com/resources/attached/image/20150521130750_804.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521130750_804.jpg\" alt=\"\"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://zhoubang85.com/resources/attached/image/20150521130803_692.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521130803_692.jpg\" alt=\"\"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从2次刷新页面的结果来看，显示的页面也不同，请求显示不同的tomcat默认页面.。也就是说这已经是tomcat集群的效果了。</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;一个请求过来，apache通过配置，来寻找应该交给哪个tomcat来处理请求，减少tomcat的负载，提高性能。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style=\"color:#337FE5;font-size:14px;\">[下面，我们加入自己的测试demo，看看结果是怎样的？]</span></strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;首先关闭2个tomcat服务，将test这个测试demo分别放在2个tomcat的webapps目录下，然后再分别启动tomcat(启动顺序随意)。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;启动的过程与平常我们使用tomcat没有什么区别，当启动完成之后，我们也可以通过http://localhost:9080/或者http://localhost:8080/ 分别访问这2个tomcat。</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;页面也会显示出对应的tomcat默认页面。说明这2个tomcat服务器并没有在我们配置集群之后，就不能分别访问和操作了。和平常没有变化。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;下面，我们就开始访问test这个测试demo，看看效果是怎样的。如果你在浏览器中输入http://localhost:9080/test或者http://localhost:8080/test&nbsp; 访问的话，其实是分别请求tomcat2和tomcat1服务器。</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这和我们说的tomcat集群，就没有啥关系了。既然已经是集群了，如何访问呢？<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;访问地址为http://localhost/test 为什么没有端口号呢？因为apache的默认端口为80，http://localhost 其实就是http://localhost:80 ，所以这个地址是被apache所解析，同时上面已经讲解了在apache中配置了2个tomcat分支节点，apache会根据配置，寻找哪个tomcat用于请求的处理。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;经过我多次的刷新页面进行访问的时候，效果如下：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://zhoubang85.com/resources/attached/image/20150521131051_212.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521131051_212.jpg\" alt=\"\"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从上图会发现，请求被分发到了2个tomcat进行处理，而不是一个tomcat处理了所有请求。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [说明]：tomcat控制台信息是test测试demo的jsp页面打印的，看过代码的朋友，就明白，其实jsp中的java代码是获取session中的数值，进行累加，然后再输出结果的。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;一个新问题出来了，请求被分发到不同的tomcat进行处理，这没有什么问题，但是，为何session中的内容没有在这2个tomcat中进行共享呢？<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;我们希望得到的结果是：页面刷新，数字应该不断增加才是，不应该为null，这和我们平时的单个tomcat处理的效果一样(单个tomcat的session是共享的)。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;那问题就严重了，要是不能共享，那做集群分发处理也没有什么意义了！只有session共享了，那么数据保持同步，不同的tomcat所访问的内容都是同步的，这就保证了数据的完整性，<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从用户的角度看，看不出来该请求其实是被多个tomcat进行分别处理的。<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:#009900;font-size:14px;\"><strong> [tomcat中session共享的集群配置]：</strong></span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分别编辑D:\\tomcat1\\conf\\server.xml和D:\\tomcat2\\conf\\server.xml文件，找到<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Cluster className=\"org.apache.catalina.ha.tcp.SimpleTcpCluster\"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></pre><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 大概在111行，将该配置的注释去掉即可. 这里的配置是为了可以在集群中的所有tomcat节点间共享会话（Session）。如果仅仅为了获得一个可用的tomcat集群，Cluster只需要这么配置就可以了。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;然后，分别在这2个test测试项目的WEB-INF\\web.xml文件中的&lt;web-app&gt;节点下加入&lt;distributable /&gt;，如果不加入这个配置，session将不能共享。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这一步非常重要，是为了通知tomcat服务器，当前应用需要在集群中的所有节点间实现Session共享。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如\n果tomcat中的所有应用都需要Session共享，也可以把conf/context.xml中的&lt;Context&gt;改\n为&lt;Context distributable=\"true\"&gt;，这样就不需对所有应用的web.xml再进行单独配置。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;配置如下：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://zhoubang85.com/resources/attached/image/20150521131427_600.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521131427_600.jpg\" alt=\"\"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;修改完成之后，分别启动这2个tomcat，然后再重新访问http://localhost/test ，效果如下：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://zhoubang85.com/resources/attached/image/20150521131517_411.jpg\" data-ke-src=\"http://zhoubang85.com/resources/attached/image/20150521131517_411.jpg\" alt=\"\"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从图中可以看出来，当我多次刷新页面重新访问的时候，2个tomcat的控制台信息打印的结果和之前的结果不一样了，session共享了。</p><p><span id=\"__kindeditor_bookmark_start_1464__\"></span></p><p><br></p>&nbsp;<strong><span style=\"color:#009900;font-size:16px;\">[补充]：</span></strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:#009900;\"><strong>[如何自定义访问的端口？]</strong></span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 上面访问的url地址是http://localhost/test,如果我希望的url为http://localhost:8558/test，该怎么办处理呢？<br><ol><li>编辑D:\\Apache2.2\\conf\\httpd.conf文件，找到Listen 80，在47行。修改成自己需要的端口号，这里我使用的端口是8558</li><li>修改了httpd.conf文件中的端口还不够，同时需要编辑D:\\Apache2.2\\conf\\extra\\httpd-vhosts.conf文件中之前配置的信息：<br><pre><code><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;VirtualHost *:80&gt;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerAdmin 842324724@qq.com<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ServerName 127.0.0.1<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ServerAlias localhost <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ProxyPassReverse / balancer://cluster/ <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ErrorLog \"logs/zb-error.log\"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomLog \"logs/zb-access.log\" common<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/VirtualHost&gt;<br></code></pre><br>将&lt;VirtualHost *:80&gt;的80修改成httpd.conf配置的端口一致，也就是8558.这样集群才正常被访问.重新启动apache，使用http://localhost:8558/test访问，看看是否访问成功！集群是否正常工作！<br><br></li></ol><p><span style=\"color:#337FE5;\">至此，apache+tomcat集群</span><span style=\"color:#337FE5;\">环境配置到此结束了。</span><br><span style=\"color:#337FE5;\">这也只是简单的入门级，我也目前只了解这么多</span><span style=\"color:#337FE5;\">了。如有什么不清楚或者不对的地方，还请大家指正。共同学习。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p><b><span style=\"color:#009900;\"><b><span style=\"color:#009900;\"><span><span style=\"font-family:&quot;color:black;background:white;\"><br></span></span></span></b></span></b></p>','2015-05-21 13:45:30','2015-05-21 13:45:30','11','1','分享给需要这方面资料的朋友，该教程是本人原创。\n[提示]：该集群是基于apache2.2版本，该版本已经集成了与tomcat服务器连接的模块，所以我们就可以省略掉以前集群配置中的复杂配置步骤。',1,NULL,1),('555f294a09439df5cc953d82','漫谈程序员系列：咦，你也在混日子啊','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-size: 14px; color: rgb(0, 176, 240);\">混日子的定义：</span></span></strong></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 240);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(0, 176, 240); font-size: 14px;\">来自百度百科的定义：“生活等方面过得不怎么好，无目标，混混沌沌。”</span></span></strong></span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 240);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(0, 176, 240); font-size: 14px;\">混日子：即没有理想，没有抱负，糊里糊涂地生活。也指工作没有责任心，得过且过。</span></span></strong><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"></span></strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;OK ，百科的定义就酱紫。</span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;那么，如何界定某一段日子是混过去的呢？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><br/></span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;首先，我们在时间轴上选取起点和终点。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;其次，回顾起点处的自己的状态（包含技能、精神、灵力等等），回顾终点处的状态，比较这两个状态，看看有没有哪方面有进步。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;假如任何一个维度都没有令人欣喜的变化，（排除自我要求过高的情况）那基本上就可以说下面这句台词儿了：“这段时间都不知道怎么混过去的，sigh……” 瞎胡混呗，我也是醉了，居然长篇大论来谈混日子……一张一弛，文武之道。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;弹簧拉得太紧，慢慢就会失去弹性。我是机器人吗？这些不是混日子的理论依据，它们只是说，人不能绷得太紧，紧过头了容易出问题。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;拿程序员来讲，有时候是忙一阵松一阵。有项目了很忙，没项目了很闲。闲的时候就容易混，反正领导也没派什么活儿，反正过一阵儿还得忙，混过这阵子再说。看起来是合理的啊，老那么忙，老加班到后半夜，谁特么受得了呢。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;那忙起来呢？其实忙又分两种情况，有目标的忙和没方向的瞎忙活。瞎忙活也是混日子的一种。看起来脚不沾地，一会儿这儿一会儿那儿，实际上干的事儿对自己都没什么意义，这就等同于混日子。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;当然这是被动的混日子。也有主动混日子的瞎忙活，就是“让自己看起来很忙”，对吧，其实我没啥事儿干，也不想干什么事儿，又担心被领导发现我闲得蛋疼，只好装装样子，让自己忙活起来。这是主动混日子。二分法，强大的二分法，我总在用。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp; &nbsp;&nbsp;扯多了，不好收场了亲。还是言归正传吧。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;混日子的合理性就在于：你没告诉我要干啥，也没告诉我干成啥样。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;其实是酱紫的：自己没有目标，加上被安排惯了，一旦没人安排他了，就只好混日子了。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><br/></span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;天天混的程序员：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;这个问题我好像提了很多遍，不过还是得提：阿猿，你为什么干开发呢？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;为了可观的薪水？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;为了享受创造的快感？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;为了自我成就与自我实现？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;鬼知道……</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;<strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">工作其实有双重意义：</span></strong></span></p><p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;挣钱养家养自己</span></strong></p><p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;自我价值的体现</span></strong></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;但实际上，有一部分程序员看的是第一个，或者干着干着，工作的意义就只剩下每月的那点儿薪水了。这样的情况，是最容易导致混日子的。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;有些程序员的一天是这么度过的：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-size: 14px; color: rgb(12, 12, 12);\">9:00 到公司</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9:00~9:30 ，吃着买来的放心早餐（包子、煎饼果子、面包等等），等待电脑启动</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9:30~10:00 ，浏览网站，看看新闻，关注一下 NBA 或者英超</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10:00~10:30 ，哎呀，今天该干点啥呢……，想着想着把页游打开了</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10:30~11:00 ，还没怎么玩呢，就十一点了啊</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;11:00~ ，收下邮件吧，看看有没有什么工作上的事儿</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;11:30~ ，吃什么呢，开始和小伙伴们商量中午吃什么</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~13:30 ，关了游戏网页，小睡一会儿</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~14:30 ，被别人叫醒了，据说有个 BUG 要处理</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14:30~15:00 ，抽根烟去，困死了</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15:00~16:30 ，打游戏，抽空浏览 JIRA ，抽空给测试 MM 说两句，就说我正在研究呢</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16:30~17:30 ，切换到 JIRA 页面，开始看 BUG 描述，告诉测试 MM 描述不清晰，无法重现，让测试 MM 再测，重现了叫他</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;17:30~ ，出去抽了根烟，回到座位上又玩了几分钟游戏，准备下班</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;特别说明：游戏只是占位符，浏览网页只是占位符，新闻只是占位符，英超只是占位符，抽烟也是占位符……可以被其它形式替换，比如找人聊聊电视剧，上个淘宝，类似的，都可以。</span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;日子，这一天天地就这么过呀……</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><br/></span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;混日子的感觉：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;我在刚参加工作时，经常会觉得自己在混日子，因为每天都在等待，等待设备出事儿，然而设备并不是分分钟都出事儿，所以就有一些时间要混过去，上网聊天，同事们聚一块打打麻将，日子就这么过去了。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;这种感觉很不好，大概是因为我虽然是个懵懂的家伙，却不是一个能心安理得混日子的人，所以混起来就有一点惶恐，一点惭愧，一点不安，一点迷惘，一点不知今夕何年的感觉。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;我不喜欢这样，感觉自己就像一块地，没人来耕种，野草野兔小鼹鼠都很 HAPPY ，我很荒芜。快乐是即兴的，转瞬即逝的，怅然若失的忧愁却是如影随形的。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;为什么没事儿干还能拿薪水你还不快乐？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;那天看到一句话：<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">不快乐是因为可以像只猪一样懒，却无法像只猪一样懒得心安理得。</span></strong></span></span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;GOD ！</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;原来如彼！</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;关键词是：<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">心安</span></strong></span>。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;我心不安宁，所以我不快乐。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;不知道你混日子的时候是什么感觉？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;干掉混日子这个魔头</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;如果你混日子混得心安理得，就别往下看了。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;为毛混日子</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;为毛混日子？这也是一个问题。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;我接触过一些程序员，表现出来的行为让人怀疑他们的想法和小学生类似：写程序是给公司写的，干活儿是给公司干的。总而言之，这就不是我的事儿，我把八小时交给你就成了。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;这也是部分程序员干活不走心的一个源头。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;不过这说到底还得赖教育，下面的话你是不是经常听到：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-size: 14px; color: rgb(12, 12, 12);\">给我好好上课</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;给我好好做作业</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;给我好好吃饭</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;给我好好玩儿</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别给我看电视</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(12, 12, 12);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;……</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;就是这样，从小我们都被教育坏了……有的人能把这种错乱纠正过来，有的人就这么一直迷惑着、迷糊着，成人了也还觉得是为别人而活，干的工作是给别人干的，谈的女盆友是给别人谈的……</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;其实，我们都是为自己而活，说为那谁谁而活，要么是自己骗自己，要么被别人骗了。既然是为自己而活，那不管干什么事儿，其实所有的付出和牺牲最终的受益人都是自己。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;那，不管你是被安排任务的码农，还是给别人安排任务的项目经理，还是被人遗忘在角落里没活儿可干的替补码字猴，日子，都是你的，你为你自己的日子负责。不想荒废，那就往下接着看吧。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;找一个目标</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;要想杜绝混日子，就得正本清源，搞明白为什么会混日子。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;其实混日子的定义里已经说了：缺乏目标。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;“人活着要有生活的目标：一辈子的目标，一段时间的目标，一个阶段的目标，一年的目标，一个月的目标，一个星期的目标，一天、一小时、一分钟的目标”。这话是列夫·托尔斯泰说的，看起来有点儿过细了是吧。我也是大部分时间松懈、想起来了紧张一下的人，我觉得目标到星期就很不错了。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;“确定了人生目标的人，比那些彷徨失措的人，起步时便已领先几十步。有目标的生活，远比彷徨的生活幸福。没有人生目标的人，人生本身就是乏味无聊的”。这话是卡耐基说的。我都说了我擅长剪报……要是你觉得自己躺枪了，也别和卡耐基计较，人已驾鹤西游了……</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;目标决定行动，找一个目标是顶顶重要的事儿。这个目标还得你愿意相信。然后，就朝着这个目标努力吧。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;在向着目标前行的过程中，也许你会感到劳累、辛酸和疲惫，不过，一切都是值得的，因为你要的幸福，就在那片更蓝的天空，只要你的翅膀卷起风暴，挣脱自我的牢笼，你就可以像狂风一样舞蹈，飞得更高。</span></p><p><br/></p>','2015-05-22 21:04:10','2015-05-22 21:04:10','2','1','混日子的定义：<br/>\n来自百度百科的定义：“生活等方面过得不怎么好，无目标，混混沌沌。”<br/>\n混日子：“即没有理想，没有抱负，糊里糊涂地生活。也指工作没有责任心，得过且过。”',1,NULL,1),('555f463009439df5cd953d82','SSO之CAS单点登录详细搭建教程','<p style=\"line-height: 1.75em;\"><span style=\"text-decoration: none; border: medium none; color: rgb(0, 176, 80);\"><strong><span style=\"border: medium none; text-decoration: none; font-family: 宋体; font-size: 14px;\">本教程是我个人编写，花费几个小时的时间，给需要学习的人员学习使用，希望能帮助到你们。</span></strong></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-family: 宋体; color: rgb(0, 176, 80); font-size: 14px;\"><br/></span></p><p style=\"line-height: 1.75em;\"><span style=\"color: rgb(255, 0, 0);\"><strong><span style=\"font-size: 14px;\">【环境说明】：</span></strong></span><span style=\"font-size: 14px;\"><br/>本文演示过程在同一个机器上的（也可以在三台实体机器或者三个的虚拟机上），环境如下：</span></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">windows7 64位</span></p></li><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">jdk1.7.0_51</span></p></li><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">apache-tomcat-7.0.57-windows-x64</span></p></li><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">cas-server-webapp-4.0.0.war、cas-client-core-3.2.1.jar、commons-logging.jar</span></p></li><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">确保本地jdk环境已经搭建好</span></p></li></ul><p style=\"line-height: 1.75em;\"><span style=\"color: rgb(255, 0, 0);\"><strong><span style=\"font-size: 14px;\">【软件说明】：</span></strong></span><span style=\"font-size: 14px;\"><br/>文档中涉及到的一些jar，还有cas服务的war，已经打包放在一起了，可以直接使用。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">根据演示需求，用修改hosts 文件的方法添加域名最简单方便（这个非常重要，因为CAS单点登录系统是基于JAVA安全证书的 https 访问， 要使用CAS单点登录必须要配置域名, cas是不能通过ip访问的.），编辑文件 C:\\Windows\\System32\\drivers\\etc\\hosts 在文件末端添加下面三条信息：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">127.0.0.1&nbsp;server.zhoubang85.com<br/>127.0.0.1&nbsp;client1.zhoubang85.com<br/>127.0.0.1&nbsp;client2.zhoubang85.com<br/></span></p></code></code></pre><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">server.zhoubang85.com&nbsp; =&gt;&gt; 对应部署cas server的tomcat，这个虚拟域名还用于服务端证书生成</span></p></li><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">client1.zhoubang85.com&nbsp; =&gt;&gt;&nbsp; 对应部署client1客户端应用的tomcat</span></p></li><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">client2.zhoubang85.com&nbsp;&nbsp; =&gt;&gt; 对应部署client2客户端应用的tomcat</span></p></li></ul><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">【<strong>注意</strong>】：上面3个ip都是127.0.0.1，这是为什么呢？因为我的环境都是在同一台机器，所以ip都是一致的，我们再把不同的服务端和客户端应用，使用不同域名加以区分。一个域名对应一个应用，模拟多端！</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">【<strong>由于CAS是基于HTTPS协议，所以需要配置服务端的tomcat，使之支持SSL安全协议访问</strong>】<br/>【<strong>说明</strong>】：当然也可以设置cas支持http访问，这个之后再补充讨论，下面先配置https协议.<br/><br/><span style=\"font-size: 14px; color: rgb(255, 0, 0);\"><strong>【安全证书配置】:</strong></span></span></p><ol class=\" list-paddingleft-2\" style=\"list-style-type: decimal;\"><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">打开cmd命令窗口</span></p></li><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">生成证书，在cmd窗口输入以下命令：</span></p></li></ol><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">keytool&nbsp;-genkey&nbsp;-alias&nbsp;ssodemo&nbsp;-keyalg&nbsp;RSA&nbsp;-keysize&nbsp;1024&nbsp;-keypass&nbsp;zhoubang&nbsp;-validity&nbsp;365&nbsp;-keystore&nbsp;c:\\zhoubang.keystore&nbsp;-storepass&nbsp;zhoubang<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><strong><span style=\"font-size: 14px;\">【说明】</span></strong><span style=\"font-size: 14px;\">：-alias后面的别名可以自定义，-keypass指定证书密钥库的密码, -storepass和前面keypass密码相同,否则下面tomcat 配置https 会访问失败 -keystore指定证书的位置,这里指定放在c盘根目录,密钥库名称可以自定义，这里是zhoubang.keystore&nbsp; &nbsp;</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. <span style=\"font-size: 14px; color: rgb(0, 176, 80);\">命令输入完成，回车之后，会提示你输入一些资料，见下图：</span></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp; </span><img alt=\"1.jpg\" src=\"/resources/attached/image/201508051438737512527038804.jpg\" title=\"201508051438737512527038804.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">【<strong>注意</strong>】：第一个让你输入的“您的名字与姓氏是什么”，请必须输入在C:\\Windows\\System32\\drivers\\etc\\hosts文件中加入的服务端的域名。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">我这里也就是server.zhoubang85.com，为何这么做？</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">首先cas只能通过域名来访问，不能通过ip访问，同时上方是生成证书，所以要求比较严格，所以如果不这么做的话，及时最终按照教程配置完成，cas也可以正常访问,访问一个客户端应用虽然能进入cas验证首页，但是，当输入信息正确后，cas在回调转入你想访问的客户端应用的时候，会出现No subject alternative names present错误异常信息，这个错误也就是在上面输入的第一个问题答案不是域名导致、或者与hosts文件配置的不一致导致。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4.<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">导出证书：</span></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;在cmd窗口继续输入以下命令，导出证书:</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">keytool&nbsp;-export&nbsp;-alias&nbsp;ssodemo&nbsp;-keystore&nbsp;c:\\zhoubang.keystore&nbsp;-file&nbsp;c:\\ssodemo.crt&nbsp;-storepass&nbsp;zhoubang<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">【<strong>说明</strong>】：-alias后面的名称要与生成证书的命令里面的alias的名称一致. –keystore后面指定证书存放的位置，这里我放在C盘根目录，同时证书名称要与【生成证书】对应的命令里的keystore名称一致.这里是zhoubang.keystore，-file后面才crt路径，我也指定在c盘根目录. –storepass的证书密码要与上面输入的密码一致.<br/>如下图所示：<br/></span><img alt=\"2.jpg\" src=\"/resources/attached/image/201508051438737551465079725.jpg\" title=\"201508051438737551465079725.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">我们再看看c盘下面是否生成crt文件:</span></p><p style=\"line-height: 1.75em;\"><img alt=\"3.jpg\" src=\"/resources/attached/image/201508051438737601496037122.jpg\" title=\"201508051438737601496037122.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5.<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">客户端导入证书</span></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;在cmd窗口输入命令:</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">keytool&nbsp;-import&nbsp;-keystore&nbsp;%JAVA_HOME%\\jre\\lib\\security\\cacerts&nbsp;-file&nbsp;c:\\&nbsp;ssodemo.crt&nbsp;-alias&nbsp;ssodemo<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">【<strong>说明</strong>】：-file指定证书的位置，也就是上一步导出证书的位置，即c:\\ ssodemo.crt 命令中指定了JAVA_HOME，意思是将证书导入到客户端证书库，也就是jdk证书库中.因为客户端应用运行在本地，需要jdk的支持。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">回车之后，会让你输入密钥库口令，注意，这里的密码必须要输入changeit，不能输入上面指定的密码zhoubang，切记，否则导入客户端证书会有问题，如果是多台机器演示，需要在每一台客户端导入该证书，步骤都是一样的。当看到提示“是否信任此证书”，输入y回车即可，见下图：(说明，命令中的-alias后面的别名可以自定义,如果出现【证书未导入，别名&lt;***&gt;已经存在】的错误，该意思是说客户端的密钥库中已经存在该别名证书了，重新指定其他别名即可.)</span></p><p style=\"line-height: 1.75em;\"><img alt=\"4.jpg\" src=\"/resources/attached/image/201508051438737630590029453.jpg\" title=\"201508051438737630590029453.jpg\"/></p><p><br/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">至此，CAS所需的证书环境，已经配置好。<br/>下面，开始我们的CAS服务、Tomcat、以及多客户端的配置及测试访问。</span></p><p><br/></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.75em;\"><span style=\"color: rgb(255, 0, 0);\"><strong><span style=\"font-size: 14px;\">部署CAS-Server相关的Tomcat</span></strong></span></p></li></ul><ol class=\" list-paddingleft-2\" style=\"list-style-type: decimal;\"><li><p style=\"line-height: 1.75em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">配置HTTPS</span></strong><span style=\"font-size: 14px;\"><br/>解压apache-tomcat-7.0.57-windows-x64.zip，我本地路径为E:\\apache-tomcat-7.0.57，编辑E:\\apache-tomcat-7.0.57\\conf\\server.xml，找到下面片段：</span></p></li></ol><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&lt;!--<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Connector&nbsp;executor=&quot;tomcatThreadPool&quot; port=&quot;8080&quot;&nbsp;protocol=&quot;HTTP/1.1&quot; connectionTimeout=&quot;20000&quot; redirectPort=&quot;8443&quot;&nbsp;/&gt;<br/>--&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">去掉注释，修改成：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&lt;Connector&nbsp;port=&quot;8443&quot;&nbsp;protocol=&quot;org.apache.coyote.http11.Http11Protocol&quot;<br/> &nbsp; &nbsp;maxThreads=&quot;150&quot;&nbsp;SSLEnabled=&quot;true&quot;&nbsp;scheme=&quot;https&quot;&nbsp;secure=&quot;true&quot;<br/> &nbsp; &nbsp;keystoreFile=&quot;C:/zhoubang.keystore&quot;&nbsp;keystorePass=&quot;zhoubang&quot;<br/> &nbsp; &nbsp;clientAuth=&quot;false&quot;&nbsp;sslProtocol=&quot;TLS&quot;&nbsp;/&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">其中，keystoreFile就是创建证书的路径，keystorePass就是创建证书的密码.</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. <span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>验证HTTPS配置</strong></span></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;其他按照默认配置不作修改，双击E:\\apache-tomcat-7.0.57\\bin \\startup.bat 启动tomcat 验证https是否配置成功，我本地使用火狐浏览器访问，在地址栏输入<br/>https://server.zhoubang85.com:8443/&nbsp; 出现下面画面，其实这就表明cas服务端tomcat的https配置是没有问题了. <br/></span><img alt=\"5.jpg\" src=\"/resources/attached/image/201508051438737693043078972.jpg\" title=\"201508051438737693043078972.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">点击【我已充分了解可能的风险】,点击出现的【添加例外】—【确认安全例外】，，将会出现下面tomcat默认首页.tomcat已经支持https协议访问了，一切ok!</span></p><p style=\"line-height: 1.75em;\"><img src=\"http://kdgx.v084.10000net.cn:80/resources/attached/image/201508051438737753965017462.jpg\" alt=\"201508051438737753965017462.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. <span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>部署CAS-Server</strong></span></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;CAS-Server 下载地址： <a _src=\"http://www.jasig.org/cas/download\" href=\"http://www.jasig.org/cas/download\">http://www.jasig.org/cas/download</a>&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;本文以cas-server-webapp-4.0.0.rar为例，解压提取cas-server-webapp-4.0.0.war文件，把改文件copy到E:\\apache-tomcat-7.0.57\\webapps 目下，并重命名为：cas.war。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;启动tomcat，在浏览器地址栏输入：https://server.zhoubang85.com:8443/cas ，回车,出现CAS服务端的登录验证首页：<br/></span><img alt=\"7.jpg\" src=\"/resources/attached/image/201508051438737814449061498.jpg\" title=\"201508051438737814449061498.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">首页默认是英文的，点击红色框的链接，切换成中文显示。当然，并不是所有的地方都会变成中文，这个不作讲解。<br/>【<strong>说明</strong>】：此时，CAS只是单独运行，至于登录的用户名和密码是什么，请查看：E:\\apache-tomcat-7.0.57\\webapps\\cas\\WEB-INF\\deployerConfigContext.xml文件中有这样一段配置：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&lt;bean&nbsp;id=&quot;primaryAuthenticationHandler&quot; class=&quot;org.jasig.cas.authentication.AcceptUsersAuthenticationHandler&quot;&gt;<br/> &nbsp; &nbsp;&lt;property&nbsp;name=&quot;users&quot;&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;map&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;entry&nbsp;key=&quot;casuser&quot;&nbsp;value=&quot;Mellon&quot;/&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/map&gt;<br/> &nbsp; &nbsp;&lt;/property&gt;<br/>&lt;/bean&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">这个配置是默认静态配置用户名和密码，那就在浏览器的CAS服务的登陆框中输入用户名casuser和密码Mellon，登录看看效果，就会出现验证成功的页面，如下图。你也可以在文件中自己配置自己的用户名和密码。</span></p><p style=\"line-height: 1.75em;\"><img alt=\"8.jpg\" src=\"/resources/attached/image/201508051438737840183043132.jpg\" title=\"201508051438737840183043132.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">看到上述页面表示CAS-Server已经部署成功。</span></p><p><br/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">用户名和密码肯定需要和数据库进行交互验证的，，那么，如何配置呢？<br/>【<strong>说明</strong>】：我本地使用的是mysql数据库。<br/>1、需要将几个jar文件，放到CAS服务的lib目录下，我本地使用的jar版本分别是c3p0-0.9.1.2.jar、cas-server-support-jdbc-4.0.0.jar、mysql-connector-java-5.1.13-bin.jar，这3个缺一不可。将这3个jar放到E:\\apache-tomcat-7.0.57\\webapps\\cas\\WEB-INF\\lib目录下。<br/>2、修改配置，支持mysql数据库交互验证<br/>编辑E:\\apache-tomcat-7.0.57\\webapps\\cas\\WEB-INF\\ deployerConfigContext.xml文件，你会看到有这样一段配置：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"9.jpg\" src=\"/resources/attached/image/201508051438737860715073078.jpg\" title=\"201508051438737860715073078.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">注释掉第二个entry配置，最终配置如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&lt;constructor-arg&gt;<br/>&nbsp;&nbsp;&lt;map&gt;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;entry&nbsp;key-ref=&quot;proxyAuthenticationHandler&quot;&nbsp;value-ref=&quot;proxyPrincipalResolver&quot;&nbsp;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;注释这个--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&lt;entry&nbsp;key-ref=&quot;primaryAuthenticationHandler&quot;&nbsp;value-ref=&quot;primaryPrincipalResolver&quot;&nbsp;/&gt;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;key-ref指定自己的本地数据库访问&nbsp;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;entry&nbsp;key-ref=&quot;dbAuthHandler&quot;&nbsp;value-ref=&quot;primaryPrincipalResolver&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&lt;/map&gt;<br/>&nbsp;&lt;/constructor-arg&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">上述配置截图：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"10.jpg\" src=\"/resources/attached/image/201508051438737881105066330.jpg\" title=\"201508051438737881105066330.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">然后再在这个xml中新加入2个bean配置，如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&lt;!--&nbsp;指定c3p0数据源&nbsp;--&gt;<br/>&lt;bean&nbsp;id=&quot;dataSource&quot;&nbsp;class=&quot;com.mchange.v2.c3p0.ComboPooledDataSource&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name=&quot;driverClass&quot;&nbsp;value=&quot;com.mysql.jdbc.Driver&quot;&nbsp;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;ame=&quot;jdbcUrl&quot;&nbsp;value=&quot;jdbc:mysql://127.0.0.1:3306/myProject?useUnicode=true&amp;amp;characterEncoding=UTF-8&quot;&nbsp;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name=&quot;user&quot;&nbsp;value=&quot;root&quot;&nbsp;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name=&quot;password&quot;&nbsp;value=&quot;root<br/>&lt;/bean&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&lt;!--&nbsp;访问本地数据库&nbsp;--&gt;<br/>&lt;bean&nbsp;id=&quot;dbAuthHandler&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class=&quot;org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p:dataSource-ref=&quot;dataSource&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p:sql=&quot;SELECT&nbsp;u.`password`&nbsp;FROM&nbsp;`sec_user`&nbsp;u&nbsp;WHERE&nbsp;u.`account`&nbsp;=&nbsp;?&quot;&nbsp;/&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">要说明的是，红色标注的内容，我想大家都能看的明白，就是指定数据库驱动和连接信息。其中，sql语句的意思就是，根据用户名获取密码，CAS会根据你页面输入的用户名获取该用户密码，和你输入的密码进行校验，来判断输入是否正确。Sql中的表换成你自己本地的表即可。只要根据用户名查询密码即可。<br/>上述配置截图：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"11.jpg\" src=\"/resources/attached/image/201508051438737902715028236.jpg\" title=\"201508051438737902715028236.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">至此，CAS与数据库交互验证的配置已经配置完成，你可以重新访问cas，输入数据库中存在的用户名和密码，来看看效果如何~如果登录成功，说明配置无误。否则，请耐心检查配置是否有问题，jar包是否缺少。<br/><br/><br/>现在，CAS已经支持数据库交互验证了，服务端tomcat也支持HTTPS协议访问，现在，我们来搭建客户端，实现多个客户端的单点登录。这里，我本地只使用2个tomcat客户端来测试，其实已经满足单点登录的要求了，至少2个应用。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4. <span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>部署CAS客户端相关的Tomcat</strong></span></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">首先，客户端应用是要和CAS服务端进行交互的，所以这里需要jar文件，放在客户端应用的lib目录下。分别是：cas-client-core-3.2.1.jar、commons-logging.jar<br/><br/>这里呢，我就直接使用tomcat默认自带的 webapps\\examples 作为演示的简单web项目。我就不去另写一个web测试的demo了。<br/>既然需要2个客户端应用，则需要2个tomcat做为客户端服务器，所以，我本地解压了2份tomcat，作为客户端服务器，并重新命名，本地路径分别为：E:\\apache-tomcat-7.0.57-client1和E:\\apache-tomcat-7.0.57-client2<br/><br/>首先，将上面2个jar分别放到E:\\apache-tomcat-7.0.57-client1\\webapps\\examples\\WEB-INF\\lib目录<br/>和E:\\apache-tomcat-7.0.57-client2\\webapps\\examples\\WEB-INF\\lib目录。</span></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.75em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">配置apache-tomcat-7.0.57-client1客户端1：</span></strong></span></p></li></ul><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;修改tomcat的启动端口：<br/>&nbsp;&nbsp;&nbsp;&nbsp;编辑E:\\apache-tomcat-7.0.57-client1\\conf\\server.xml文件，找到如下2处内容：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&lt;Connector&nbsp;port=&quot;8080&quot;&nbsp;protocol=&quot;HTTP/1.1&quot; connectionTimeout=&quot;20000&quot; redirectPort=&quot;8443&quot;&nbsp;/&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">这里请将port=&quot;8080&quot;修改成其他4位端口，不能和CAS服务端的tomcat相同，否则，在同一台机器上测试会出现端口占用的错误，我修改成18080，如果是在不同的机器上，则不需要配置这些。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&lt;Connector&nbsp;port=&quot;8009&quot;&nbsp;protocol=&quot;AJP/1.3&quot;&nbsp;redirectPort=&quot;8443&quot;&nbsp;/&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">这里请将port=&quot;8009&quot;修改成其他4位端口，不能和CAS服务端相同.我修改成18009</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">好，启动这个tomcat，即运行E:\\apache-tomcat-7.0.57-client1\\bin\\startup.bat，如果启动窗口中没有出现错误，说明端口配置无误。请记住你配置的端口号。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">浏览器输入 http://client1.zhoubang85.com:18080/examples/servlets/，请注意红色部分域名,就是教程一开始需要配置的C:\\Windows\\System32\\drivers\\etc\\hosts的域名，用于不同的客户端域名访问，回车：<br/></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">好，启动这个tomcat，即运行E:\\apache-tomcat-7.0.57-client1\\bin\\startup.bat ，如果启动窗口中没有出现错误，说明端口配置无误。请记住你配置的端口号。</span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">浏览器输入 </span><a style=\"text-decoration: underline; font-size: 14px;\" _src=\"http://client1.zhoubang85.com:18080/examples/servlets/，\" href=\"http://client1.zhoubang85.com:18080/examples/servlets/，\"><span style=\"font-size: 14px;\">http://client1.zhoubang85.com:18080/examples/servlets/，</span></a><span style=\"font-size: 14px;\">&nbsp; 请注意红色部分域名,就是教程一开始需要配置的 C:\\Windows\\System32\\drivers\\etc\\hosts 的域名，用于不同的客户端域名访问，回车：<br/></span></p><p style=\"line-height: 1.75em;\"><img alt=\"12.jpg\" src=\"/resources/attached/image/201508051438737926433068850.jpg\" title=\"201508051438737926433068850.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">看到上述界面表示apache-tomcat-7.0.57-client1的基本安装配置已经成功。<br/>接下来需要配置最重要的内容，让客户端应用和CAS服务连接：<br/>编辑E:\\apache-tomcat-7.0.57-client1\\webapps\\examples\\WEB-INF\\web.xml，在最下面加入如下配置：<br/></span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\"> &nbsp; &nbsp;&lt;!--&nbsp;用于单点退出，该过滤器用于实现单点登出功能，可选配置--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;listener&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;listener-class&gt;org.jasig.cas.client.session.SingleSignOutHttpSessionListener&lt;/listener-class&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/listener&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;该过滤器用于实现单点登出功能，可选配置&nbsp;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Single&nbsp;Sign&nbsp;Out&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-class&gt;org.jasig.cas.client.session.SingleSignOutFilter&lt;/filter-class&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-mapping&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Single&nbsp;Sign&nbsp;Out&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter-mapping&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;/filter-class&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-value&gt;https://server.zhoubang85.com:8443/cas/login&lt;/param-value&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-name&gt;serverName&lt;/param-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-value&gt;http://client1.zhoubang85.com:18080&lt;/param-value&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-mapping&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter-mapping&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;该过滤器负责对Ticket的校验工作，必须启用它&nbsp;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Validation&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-class&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;org.jasig.cas.client.validation.Cas10TicketValidationFilter&lt;/filter-class&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-name&gt;casServerUrlPrefix&lt;/param-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-value&gt;https://server.zhoubang85.com:8443/cas&lt;/param-value&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-name&gt;serverName&lt;/param-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param-value&gt;http://client1.zhoubang85.com:18080&lt;/param-value&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/init-param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-mapping&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Validation&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter-mapping&gt;<br/> &nbsp; &nbsp;&lt;!--<br/>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;该过滤器负责实现HttpServletRequest请求的包裹，比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得SSO登录用户的登录名，可选配置。<br/>&nbsp;&nbsp;&nbsp;&nbsp;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS&nbsp;HttpServletRequest&nbsp;Wrapper&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&lt;filter-class&gt;org.jasig.cas.client.util.HttpServletRequestWrapperFilter&lt;/filter-class&gt;<br/> &nbsp; &nbsp;&lt;/filter&gt;<br/> &nbsp; &nbsp;&lt;filter-mapping&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS&nbsp;HttpServletRequest&nbsp;Wrapper&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/> &nbsp; &nbsp;&lt;/filter-mapping&gt;<br/> &nbsp; &nbsp;&lt;!--<br/>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。比如AssertionHolder.getAssertion().getPrincipal().getName()。<br/> &nbsp; &nbsp;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Assertion&nbsp;Thread&nbsp;Local&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-class&gt;org.jasig.cas.client.util.AssertionThreadLocalFilter&lt;/filter-class&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-mapping&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;CAS&nbsp;Assertion&nbsp;Thread&nbsp;Local&nbsp;Filter&lt;/filter-name&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter-mapping&gt;<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">配置完成后，启动CAS服务端tomcat，再启动该客户端1的tomcat，在浏览器访问:<br/>http://client1.zhoubang85.com:18080/examples/servlets/servlet/HelloWorldExample<br/>看看是否跳转到了CAS认证界面，回车之后，会出现如下图：<br/></span><img alt=\"13.jpg\" src=\"/resources/attached/image/201508051438737950449029120.jpg\" title=\"201508051438737950449029120.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">认证观察会发现浏览器的地址栏中（我用的是火狐浏览器），URL信息是这样的：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">https://server.zhoubang85.com:8443/cas/login?service=http%3A%2F%2Fclient1.zhoubang85.com%3A18080%2Fexamples%2Fservlets%2Fservlet%2FHelloWorldExample<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">我想你已经知道什么意思了，由于你没有登录CAS认证系统，CAS认证系统拦截到你访问的客户端应用，首先进入到认证系统登录界面，同时URL后面加上你想访问的地址信息，当你登录成功后，CAS服务会转向到你刚刚访问的地址，也就是：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">http://client1.zhoubang85.com:18080/examples/servlets/servlet/HelloWorldExample<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">转向到这个地址之后，浏览器会显示如下内容：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"14.jpg\" src=\"/resources/attached/image/201508051438737968793091154.jpg\" title=\"201508051438737968793091154.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">上面这个内容，显示的就是你访问tomcat中的examples项目的一个servlet的返回结果。<br/>这里，如果你够细心的话，你会发现浏览器地址栏又多了一个内容，即多了一个jsessionid参数，这个就是CAS认证的原理所在，使用的是COOKIE机制。这里就不多说了。<br/></span></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.75em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">配置apache-tomcat-7.0.57-client2客户端2</span></strong></span></p></li></ul><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;配置与上面的客户端配置步骤相同，其中需要注意的就是，这第二个客户端的tomcat端口要与上面的客户端和CAS服务端的端口要不一样，否则出现端口占用的错误。<br/>&nbsp;&nbsp;&nbsp;&nbsp;主要配置如下：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"15.jpg\" src=\"/resources/attached/image/201508051438737989855041373.jpg\" title=\"201508051438737989855041373.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">Port修改成28080</span></span></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\"><br/></span></p><p style=\"line-height: 1.75em;\"><img alt=\"16.jpg\" src=\"/resources/attached/image/201508051438738005012027414.jpg\" title=\"201508051438738005012027414.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">Port修改成28009</span></span></p><p><br/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;修改编辑E:\\apache-tomcat-7.0.57-client2\\webapps\\examples\\WEB-INF\\web.xml文件，加入的内容就是上面在第一个客户端的web.xml内容一致，只不过需要修改2处内容，就是几个url地址， 最终的配置如下:</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\"> &nbsp; &nbsp;&lt;!-- 用于单点退出，该过滤器用于实现单点登出功能，可选配置--&gt;<br/> &nbsp; &nbsp;&lt;listener&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;listener-class&gt;org.jasig.cas.client.session.SingleSignOutHttpSessionListener&lt;/listener-class&gt;<br/> &nbsp; &nbsp;&lt;/listener&gt;<br/> &nbsp; &nbsp;&lt;!-- 该过滤器用于实现单点登出功能，可选配置 --&gt;<br/> &nbsp; &nbsp;&lt;filter&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-class&gt;org.jasig.cas.client.session.SingleSignOutFilter&lt;/filter-class&gt;<br/> &nbsp; &nbsp;&lt;/filter&gt;<br/> &nbsp; &nbsp;&lt;filter-mapping&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/> &nbsp; &nbsp;&lt;/filter-mapping&gt;<br/> &nbsp; &nbsp;&lt;filter&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;/filter-class&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;init-param&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-value&gt;https://server.zhoubang85.com:8443/cas/login&lt;/param-value&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/init-param&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;init-param&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-name&gt;serverName&lt;/param-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-value&gt;http://client2.zhoubang85.com:28080&lt;/param-value&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/init-param&gt;<br/> &nbsp; &nbsp;&lt;/filter&gt;<br/> &nbsp; &nbsp;&lt;filter-mapping&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/> &nbsp; &nbsp;&lt;/filter-mapping&gt;<br/> &nbsp; &nbsp;&lt;!-- 该过滤器负责对Ticket的校验工作，必须启用它 --&gt;<br/> &nbsp; &nbsp;&lt;filter&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-class&gt;org.jasig.cas.client.validation.Cas10TicketValidationFilter&lt;/filter-class&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;init-param&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-name&gt;casServerUrlPrefix&lt;/param-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-value&gt;https://server.zhoubang85.com:8443/cas&lt;/param-value&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/init-param&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;init-param&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-name&gt;serverName&lt;/param-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;param-value&gt;http://client2.zhoubang85.com:28080&lt;/param-value&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/init-param&gt;<br/> &nbsp; &nbsp;&lt;/filter&gt;<br/> &nbsp; &nbsp;&lt;filter-mapping&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/> &nbsp; &nbsp;&lt;/filter-mapping&gt;<br/> &nbsp; &nbsp;&lt;!--<br/> &nbsp; &nbsp; &nbsp; &nbsp;该过滤器负责实现HttpServletRequest请求的包裹，比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得SSO登录用户的登录名，可选配置。<br/> &nbsp; &nbsp;--&gt;<br/> &nbsp; &nbsp;&lt;filter&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS HttpServletRequest Wrapper Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-class&gt;org.jasig.cas.client.util.HttpServletRequestWrapperFilter&lt;/filter-class&gt;<br/> &nbsp; &nbsp;&lt;/filter&gt;<br/> &nbsp; &nbsp;&lt;filter-mapping&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS HttpServletRequest Wrapper Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/> &nbsp; &nbsp;&lt;/filter-mapping&gt;<br/> &nbsp; &nbsp;&lt;!--<br/> &nbsp; &nbsp; &nbsp; &nbsp;该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。比如AssertionHolder.getAssertion().getPrincipal().getName()。<br/> &nbsp; &nbsp;--&gt;<br/> &nbsp; &nbsp;&lt;filter&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Assertion Thread Local Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-class&gt;org.jasig.cas.client.util.AssertionThreadLocalFilter&lt;/filter-class&gt;<br/> &nbsp; &nbsp;&lt;/filter&gt;<br/> &nbsp; &nbsp;&lt;filter-mapping&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;filter-name&gt;CAS Assertion Thread Local Filter&lt;/filter-name&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br/> &nbsp; &nbsp;&lt;/filter-mapping&gt;<br/></span></p></code></code></pre><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">测试验证SSO</span></p></li></ul><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;至此，2个客户端也已经配置完毕，启动配置好的三个tomcat分别为：CAS服务端tomcat、2个客户端tomcat<br/>&nbsp;&nbsp;&nbsp;&nbsp;我本地路径分别为：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;服务端tomcat：E:\\apache-tomcat-7.0.57<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;客户端1：E:\\apache-tomcat-7.0.57-client1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;客户端2：E:\\apache-tomcat-7.0.57-client2</span></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">基本的测试</span></p></li></ul><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;访问客户端1—-&gt; 跳转到cas server 验证 —-&gt; 显示客户端1的应用 —-&gt;新开选项卡访问客户端2 —-&gt; 显示客户端2应用 —-&gt; 注销cas server —-&gt; 打开客户端1/客户端2 —-&gt; 重新跳转到cas server 验证.</span></p><p><br/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">下面截图，根据上面所示进行测试，看看是否与上面说的流程一致：<br/>首先，打开火狐浏览器，地址栏输入：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">http://client1.zhoubang85.com:18080/examples/servlets/servlet/HelloWorldExample<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">回车，将会出现CAS认证界面：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"17.jpg\" src=\"/resources/attached/image/201508051438738027152022723.jpg\" title=\"201508051438738027152022723.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">输入用户名和密码，登录成功后，显示的界面：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"18.jpg\" src=\"/resources/attached/image/201508051438738043402095158.jpg\" title=\"201508051438738043402095158.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">重新打开一个选项卡，地址栏输入：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">http://client2.zhoubang85.com:28080/examples/servlets/servlet/HelloWorldExample<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">回车，将直接显示客户端2界面，没有重新登录，浏览器显示界面：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"19.jpg\" src=\"/resources/attached/image/201508051438738060808083728.jpg\" title=\"201508051438738060808083728.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">根据上面显示的界面，按照普通想逻辑，当访问客户端2的时候，应该会被CAS拦截，转到CAS认证服务的界面，但是结果却直接显示客户端2的界面，原因就是因为你在访问客户端1的时候已经登录认证过了，CAS会在你浏览器中注入COOKIE，记录你的认证凭证，如果你的浏览器没有关闭或者退出的话，当你访问客户端2应用的时候，CAS检测到认证的凭证，所以，就直接显示了客户端2的界面，大概的认证处理流程就是这样了，我这里说的比较浅显，其实CAS还是有很多更加复杂的操作在里面的，有兴趣的朋友自己慢慢研究吧。</span></p><p><br/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">这里，其实就已经说明，CAS单点登录系统已经搭建完毕！运行一切正常！<br/><br/>下面，我们新打开一个选项卡(也可在当前页面的地址栏输入)，在浏览器地址栏中输入</span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">https://server.zhoubang85.com:8443/cas/logout<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">回车显示：</span></p><p style=\"line-height: 1.75em;\"><img alt=\"20.jpg\" src=\"/resources/attached/image/201508051438738078027069738.jpg\" title=\"201508051438738078027069738.jpg\"/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">上述表示 认证注销成功，此时如果再访问 : <br/></span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">http://client1.zhoubang85.com:18080/examples/servlets/servlet/HelloWorldExample<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">或 <br/></span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">http://client2.zhoubang85.com:28080/examples/servlets/servlet/HelloWorldExample<br/></span></p></code></code></pre><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">都将会跳转到CAS服务重新进行认证。</span></p><p><br/></p><p style=\"line-height: 1.75em;\"><span style=\"font-size: 14px;\">到此，SSO之CAS单点登录系统已经搭建完毕！<br/>这里我借鉴一篇文章，提供大家学习：<br/>http://www.micmiu.com/enterprise-app/sso/sso-cas-sample/<br/><br/>当然，CAS认证之后，至于在后台如何获取到登录的用户信息，这里我就不作描述了。该文章最后有相应的讲解。其他的知识，自己慢慢学习和研究吧。</span></p><p><br/></p><p><br/></p>','2015-05-22 23:07:29','2015-05-22 23:07:29','12','1','本教程是我个人编写，花费几个小时的时间，给需要学习的人员学习使用，希望能帮助到你们。',1,NULL,1),('556321a66ec09df592a730ed','JVM加载class文件的原理机制','<p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>1.Java中的所有类，必须被装载到jvm中才能运行，这个装载工作是由jvm中的类装载器完成的</strong></span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;类装载器所做的工作实质是把类文件从硬盘读取到内存中</span></p><p style=\"line-height: normal;\"><strong><span style=\"margin: 0px; padding: 0px; font-size: 14px; color: rgb(0, 176, 80);\">2.java中的类大致分为三种：&nbsp;</span></strong></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 1.系统类&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 2.扩展类&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 3.由程序员自定义的类</span></p><p style=\"line-height: normal;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">3.类装载方式，有两种&nbsp;</span></strong></span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 1.隐式装载， 程序在运行过程中当碰到通过new 等方式生成对象时，隐式调用类装载器加载对应的类到jvm中，&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 2.显式装载， 通过class.forname()等方法，显式加载需要的类 </span><span style=\"margin: 0px; padding: 0px; font-size: 12px;\"><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;隐式加载与显式加载的区别：&nbsp;两者本质是一样的！都是加载到JVM虚拟机中。</span></p><p style=\"line-height: normal;\"><strong><span style=\"margin: 0px; padding: 0px; font-size: 14px; color: rgb(0, 176, 80);\">4.类加载的动态性体现&nbsp;</span></strong></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个应用程序总是由n多个类组成，Java程序启动时，并不是一次把所有的类全部加载后再&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">运行，它总是先把保证程序运行的基础类一次性加载到jvm中，其它类等到jvm用到的时候再加载，这样的好处是节省了内存的开销，因为java最早就是为嵌入式系统而设计的，内存宝贵，这是一种可以理解的机制，而用到时再加载这也是java动态性的一种体现</span></p><p><br/></p><p style=\"line-height: normal;\"><strong><span style=\"margin: 0px; padding: 0px; font-size: 14px; color: rgb(0, 176, 80);\">5．java类装载器&nbsp;</span></strong></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; Java中的类装载器实质上也是类，功能是把类载入jvm中，值得注意的是jvm的类装载器并不是一个，而是三个，层次结构如下：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; &nbsp; Bootstrap Loader &nbsp;- 负责加载系统类&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - - ExtClassLoader &nbsp;- 负责加载扩展类&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - - AppClassLoader &nbsp;- 负责加载应用类&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; &nbsp; &nbsp; 为什么要有三个类加载器，一方面是分工，各自负责各自的区块，另一方面为了实现委托模型，下面会谈到该模型</span></p><p><br/></p><p style=\"line-height: normal;\"><strong><span style=\"margin: 0px; padding: 0px; font-size: 14px; color: rgb(0, 176, 80);\">6. 类加载器之间是如何协调工作的&nbsp;</span></strong></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp;前面说了，java中有三个类加载器，问题就来了，碰到一个类需要加载时，它们之间是如何协调工作的，即java是如何区分一个类该由哪个类加载器来完成呢。&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在这里java采用了委托模型机制，这个机制简单来讲，就是“类装载器有载入类的需求时，会先请示其Parent使用其搜索路径帮忙载入，如果Parent 找不到,那么才由自己依照自己的搜索路径搜索类”，注意喔，这句话具有递归性&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">下面举一个例子来说明，为了更好的理解，先弄清楚几行代码：&nbsp;</span></p><pre class=\"brush:java;toolbar:false\"><code>Public&nbsp;class&nbsp;Test{&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;Public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;arg){&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ClassLoader&nbsp;c&nbsp;&nbsp;=&nbsp;Test.class.getClassLoader();&nbsp;&nbsp;//获取Test类的类加载器&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(c);&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ClassLoader&nbsp;c1&nbsp;=&nbsp;c.getParent();&nbsp;&nbsp;//获取c这个类加载器的父类加载器&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(c1);&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ClassLoader&nbsp;c2&nbsp;=&nbsp;c1.getParent();//获取c1这个类加载器的父类加载器&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(c2);&nbsp;\n&nbsp;&nbsp;}&nbsp;\n}</code></pre><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">把以上代码存到d:\\my 文件夹下，直接编译，然后在dos模式下运行&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my\\java Test&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 。。。AppClassLoader。。。&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 。。。ExtClassLoader。。。&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; Null</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\"><br/></span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">注： 。。。表示省略了内容&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">可以看出Test是由AppClassLoader加载器加载的&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">AppClassLoader的Parent 加载器是 ExtClassLoader</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">但是ExtClassLoader的Parent为 null 是怎么回事呵，朋友们留意的话，前面有提到Bootstrap Loader是用C++语言写的,依java的观点来看，逻辑上并不存在Bootstrap Loader的类实体，所以在java程序代码里试图打印出其内容时，我们就会看到输出为null&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">【注：以下内容大部分引用java深度历险】&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">弄明白了上面的示例，接下来直接进入类装载的委托模型实例，写两个文件，如下：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">文件：Test1.java&nbsp;</span></p><pre class=\"brush:java;toolbar:false\"><code>Public&nbsp;class&nbsp;Test1{&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;Public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;arg){&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Test1.class.getClassLoader());&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Test2&nbsp;t2&nbsp;=&nbsp;new&nbsp;Test2();&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T2.print();&nbsp;\n&nbsp;&nbsp;}&nbsp;\n}</code></pre><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">文件： Test2.java&nbsp;</span></p><pre class=\"brush:java;toolbar:false\"><code>Public&nbsp;class&nbsp;Test2{&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;Public&nbsp;void&nbsp;prin(){&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(this.getClass().getClassLoader());&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;\n}</code></pre><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">这两个类的作用就是打印出载入它们的类装载器是谁， 将这两个文件保存到d:\\my目录下，编译后，我们在复制两份，分别置于 &lt;JRE所在目录&gt;\\classes下（注意，刚开始我们的系统下没有此目录，需自己建立） 与 &lt;JRE所在目录&gt;\\lib\\ext\\classes下（同样注意，开始我们的系统下也没此目录，手工建立）, 然后切换到d:\\my目录下开始测试，</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">测试一：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\classes下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\lib\\ext\\classes下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">dos下输入运行命令，结果如下：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my&gt;java Test1&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Null&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Null</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\"><br/></span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my&gt;&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp;&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;从输出结果我们可以看出，当AppClassLoader要载入Test1.class时，先请其Parent，也就是ExtClassLoader来载 入，而ExtclassLoader又请求其Parent,即Bootstrap Loader来载入Test1.class. 由于 &lt;JRE所在目录&gt;\\Classes目录为Bootstrap Loader的搜索路径之一，所以Bootstrap Loader找到了Test1.class,因此将它载入，接着在Test1.class之内有载入Test2.class的需求，由于 Test1.class是由Bootstrap Loader所载入，所以Test2.class内定是由Bootstrap Loader根据其搜索路径来找，因Test2.class也位于Bootstrap Loader可以找到的路径下，所以也被载入了，最后我们看到Test1.class与Test2.class都是由Bootstrap Loader（null）载入。</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">测试二：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\classes下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\lib\\ext\\classes下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">dos下输入运行命令，结果如下：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my&gt;java Test1&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Null&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Exception in thread “main” java.lang.NoClassdefFoundError:Test2 at Test1.main。。。&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my&gt;</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 从输出结果我们可以看出，当AppClassLoader要载入Test1.class时，先请其Parent，也就是ExtClassLoader来载 入，而ExtclassLoader又请求其Parent,即Bootstrap Loader来载入Test1.class. 由于 &lt;JRE所在目录&gt;\\Classes目录为Bootstrap Loader的搜索路径之一，所以Bootstrap Loader找到了Test1.class,因此将它载入，接着在Test1.class之内有载入Test2.class的需求，由于 Test1.class是由Bootstrap Loader所载入，所以Test2.class内定是由Bootstrap Loader根据其搜索路径来找，但是因为Bootstrap Loader根本找不到Test2.class（被我们删除了），而Bootstrap Loader又没有Parent，所以无法载入Test2.class.最后我们看到Test1.class是由Bootstrap Loader（null）载入，而Test2.class则无法载入</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">测试三&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\classes下</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\lib\\ext\\classes下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">dos下输入运行命令，结果如下：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my&gt;java Test1&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">。。。ExtClassLoader。。。&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Null</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\"><br/></span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my&gt;</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&nbsp; &nbsp; 从输出结果我们可以看出，当AppClassLoader要载入Test1.class时，先请其Parent，也就是ExtClassLoader来载 入，而ExtclassLoader又请求其Parent,即Bootstrap Loader来载入Test1.class.但是Bootstrap Loader无法在其搜索路径下找到Test1.class(被我们删掉了)，所以ExtClassLoader只得自己搜索，因此 ExtClassLoader在其搜索路径 &lt;JRE所在目录&gt;\\lib\\ext\\classes下找到了Test1.class,因此将它载入，接着在Test1.class之内有载 入Test2.class的需求，由于Test1.class是由ExtClassLoader所载入，所以Test2.class内定是由 ExtClassLoader根据其搜索路径来找，但是因为ExtClassLoader有Parent,所以先由Bootstrap Loader帮忙寻找，Test2.class位于Bootstrap Loader可以找到的路径下，所以被Bootstrap Loader载入了.最后我们看到Test1.class是由ExtClassLoader载入，而Test2.class则是由Bootstrap Loader（null）载入</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">了解了以上规则，请朋友们自行分析以下场景的执行结果</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">测试四：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\classes下</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\lib\\ext\\classes下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">测试五：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\classes下</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\lib\\ext\\classes下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">测试六：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\classes下</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\lib\\ext\\classes下</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\"><br/></span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">测试七：&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\classes下</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">&lt;JRE所在目录&gt;\\lib\\ext\\classes下</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\"><br/></span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">D:\\my下&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test1.class&nbsp;</span></p><p style=\"line-height: normal;\"><span style=\"margin: 0px; padding: 0px; font-size: 14px;\">Test2.class</span></p><p><br/></p>','2015-05-25 21:20:39','2015-05-25 21:20:39','55631ee26ec09df591a730ed','1','Java中的所有类，必须被装载到jvm中才能运行，这个装载工作是由jvm中的类装载器完成的<br>\n类装载器所做的工作实质是把类文件从硬盘读取到内存中 ',1,NULL,1),('5565da106ec09df594a730ed','maven编译的时候排除junit测试类','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">maven项目中使用junit进行单元测试，在进行编译的时候，可以通过2种方式排除test测试类的编译。</span></strong></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">有2种方式 ：</span></strong></span></p><ol style=\"list-style-type: num;\" class=\"custom_num list-paddingleft-1\"><li class=\"list-num-1-1 list-num-paddingleft-1\"><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">使用命令的时候带上参数</span></p></li></ol><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">mvn install -Dmaven.test.skip=true<br/></span></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 在pom.xml里面配置</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&lt;plugins&gt;<br/> &nbsp; &nbsp;&lt;plugin&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;configuration&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;skip&gt;true&lt;/skip&gt;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&lt;/configuration&gt;<br/> &nbsp; &nbsp;&lt;/plugin&gt;<br/>&lt;/plugins&gt;<br/></span></p></code></pre><p><br/></p>','2015-05-27 22:52:00','2015-05-27 22:52:00','55631ee26ec09df591a730ed','1','maven项目中使用junit进行单元测试，在进行编译的时候，可以通过2种方式排除test测试类的编译',1,NULL,1),('5565e2a96ec09df595a730ed','JSP页面之${fn：}内置函数','<p><span style=\"font-size: 16px;\"><strong><span style=\"color: rgb(0, 176, 80);\">函数列表：</span></strong></span></p><table height=\"606\" width=\"1001\"><tbody><tr class=\"firstRow\"><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">函数名<br/></span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">函数说明</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">使用举例<br/></span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:contains<br/></span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">判断字符串是否包含另外一个字符串</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">&lt;c:if test=&quot;${fn:contains(name, searchString)}&quot;&gt;</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:containsIgnoreCase</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">判断字符串是否包含另外一个字符串(大小写无关)</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">&lt;c:if test=&quot;${fn:containsIgnoreCase(name, searchString)}&quot;&gt;</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:endsWith</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">判断字符串是否以另外字符串结束</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">&lt;c:if test=&quot;${fn:endsWith(filename, &quot;.txt&quot;)}&quot;&gt;</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:escapeXml</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">把一些字符转成XML表示，例如 &lt;字符应该转为&amp;lt;</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">${fn:escapeXml(param:info)}</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:indexOf</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">子字符串在母字符串中出现的位置</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">${fn:indexOf(name, &quot;-&quot;)}</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:join</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">将数组中的数据联合成一个新字符串，并使用指定字符格开</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">${fn:join(array, &quot;;&quot;)}</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:length</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">获取字符串的长度 ，或者数组的大小</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">${fn:length(shoppingCart.products)}</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:replace</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">替换字符串中指定的字符</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">${fn:replace(text, &quot;-&quot;, &quot;&amp;#149;&quot;)}</span></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:startsWith</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">判断字符串是否以某个子串开始</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">&lt;c:if test=&quot;${fn:startsWith(product.id, &quot;100-&quot;)}&quot;&gt;</span></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:substring</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">获取子串</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">${fn:substring(zip, 6, -1)}</span></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:substringBefore</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">获取从开始到某个字符所在位置的子串</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">${fn:substringBefore(zip, &quot;-&quot;)}</span></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:toLowerCase</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">转为小写</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">${fn.toLowerCase(product.name)}</span></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:trim</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">去除字符串前后的空格</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">${fn.trim(name)}</span></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:toUpperCase</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">转为大写字符</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">${fn.UpperCase(product.name)}</span></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:substringAfter</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">获取从某个字符所在位置开始的子串</span></td><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><span style=\"font-size: 14px;\">${fn:substringAfter(zip, &quot;-&quot;)}</span></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"170\"><span style=\"font-size: 14px;\">fn:split</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">把字符串按照指定字符切分</span></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><span style=\"font-size: 14px;\">${fn:split(customerNames, &quot;;&quot;)}</span></td></tr></tbody></table><p><br/></p><p><span style=\"font-size: 16px;\"><strong><span style=\"color: rgb(0, 176, 80);\">函数描述：</span></strong></span></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p><span style=\"font-size: 14px;\">fn:contains(string, substring) —— 如果参数string中包含参数substring，返回true</span></p></li><li><p><span style=\"font-size: 14px;\">fn:containsIgnoreCase(string, substring) —— 如果参数string中包含参数substring（忽略大小写），返回true</span></p></li><li><p><span style=\"font-size: 14px;\">fn:endsWith(string, suffix) —— 如果参数 string 以参数suffix结尾，返回true</span></p></li><li><p><span style=\"font-size: 14px;\">fn:escapeXml(string) —— 将有特殊意义的XML (和HTML)转换为对应的XML character entity code，并返回</span></p></li><li><p><span style=\"font-size: 14px;\">fn:indexOf(string, substring) —— 返回参数substring在参数string中第一次出现的位置</span></p></li><li><p><span style=\"font-size: 14px;\">fn:join(array, separator) —— 将一个给定的数组array用给定的间隔符separator串在一起，组成一个新的字符串并返回。</span></p></li><li><p><span style=\"font-size: 14px;\">fn:length(item) —— 返回参数item中包含元素的数量。参数Item类型是数组、collection或者String。如果是String类型,返回值是String中的 字符数。</span></p></li><li><p><span style=\"font-size: 14px;\">fn:replace(string, before, after) —— 返回一个String对象。用参数after字符串替换参数string中所有出现参数before字符串的地方，并返回替换后的结果</span></p></li><li><p><span style=\"font-size: 14px;\">fn:split(string, separator) —— 返回一个数组，以参数separator 为分割符分割参数string，分割后的每一部分就是数组的一个元素</span></p></li><li><p><span style=\"font-size: 14px;\">fn:startsWith(string, prefix) —— 如果参数string以参数prefix开头，返回true</span></p></li><li><p><span style=\"font-size: 14px;\">fn:substring(string, begin, end) —— 返回参数string部分字符串, 从参数begin开始到参数end位置，包括end位置的字符</span></p></li><li><p><span style=\"font-size: 14px;\">fn:substringAfter(string, substring) —— 返回参数substring在参数string中后面的那一部分字符串</span></p></li><li><p><span style=\"font-size: 14px;\">fn:substringBefore(string, substring) —— 返回参数substring在参数string中前面的那一部分字符串</span></p></li><li><p><span style=\"font-size: 14px;\">fn:toLowerCase(string) —— 将参数string所有的字符变为小写，并将其返回</span></p></li><li><p><span style=\"font-size: 14px;\">fn:toUpperCase(string) —— 将参数string所有的字符变为大写，并将其返回</span></p></li><li><p><span style=\"font-size: 14px;\">fn:trim(string) —— 去除参数string 首尾的空格 ，并将其返回<br/></span></p></li></ul><p><br/></p>','2015-05-27 23:28:41','2015-05-27 23:28:41','5','1','jsp页面内置的函数，方便页面处理数据。<br/>\n引入这样一个头文件<%@ taglib prefix=\"fn\" uri=\"http://java.sun.com/jsp/jstl/functions \" %><br/>',1,NULL,1),('556702fd6ec09df597a730ed','mysql之——存储过程 + 游标 + 事务','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">下面是自己曾经编写过的mysql数据库存储过程，留作存档，以后用到的时候拿来参考。</span></strong></p><p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">其中，涉及到了存储过程、游标（双层循环）、事务。</span></strong></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px; color: rgb(255, 0, 0);\">【说明】：</span><strong><span style=\"font-size: 14px; color: rgb(255, 0, 0);\"><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">代码中的注释只针对当时业务而言，无须理会。</span></span></strong><span style=\"font-size: 14px;\"><br/></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">代码如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">DELIMITER $$<br/>DROP PROCEDURE IF EXISTS `transferEmailTempData`$$<br/><br/>CREATE PROCEDURE transferEmailTempData(IN jobId VARCHAR(24))<br/>BEGIN<br/> &nbsp; &nbsp;DECLARE idval VARCHAR(24) DEFAULT &#39;&#39;;<br/> &nbsp; &nbsp;DECLARE taskIdval VARCHAR(24) DEFAULT &#39;&#39;;<br/> &nbsp; &nbsp;DECLARE groupIdval VARCHAR(24) DEFAULT &#39;&#39;;<br/> &nbsp; &nbsp;DECLARE emailval VARCHAR(50) DEFAULT &#39;&#39;;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*标识正式表是否存在一条相同数据，即：groupId、email相同*/<br/> &nbsp; &nbsp;DECLARE infoId VARCHAR(24) DEFAULT &#39;&#39;;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*标识事务错误*/<br/> &nbsp; &nbsp;DECLARE err INT DEFAULT 0;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*达到一定数量就进行提交，计数器*/<br/> &nbsp; &nbsp;DECLARE counts INT DEFAULT 0;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*标识是否回滚过*/<br/> &nbsp; &nbsp;DECLARE isrollback INT DEFAULT 0;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*游标遍历时，作为判断是否遍历完全部记录的标记*/<br/> &nbsp; &nbsp;DECLARE done INTEGER DEFAULT 0;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*获取临时表该任务的数据*/<br/> &nbsp; &nbsp;DECLARE cur CURSOR FOR SELECT id,taskId,groupId,email FROM `t_email_data_temp` WHERE taskId=jobId;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*根据群组id、email查询是否存在相同记录*/<br/> &nbsp; &nbsp;DECLARE cur2 CURSOR FOR SELECT id FROM `t_email_info` e WHERE e.`group_id` = groupIdval AND e.`email_address` = emailval; <br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/* 出现错误，设置为1，只要发生异常就回滚*/<br/> &nbsp; &nbsp;DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET err=1;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*声明当游标遍历完全部记录后将标志变量置成某个值*/<br/> &nbsp; &nbsp;DECLARE CONTINUE HANDLER FOR NOT FOUND<br/> &nbsp; &nbsp;SET done=1;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*开启事务*/<br/> &nbsp; &nbsp;START TRANSACTION;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*打开游标*/<br/> &nbsp; &nbsp;OPEN cur;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*使用LOOP循环遍历*/<br/> &nbsp; &nbsp;out_loop:LOOP<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;/*将每一条结果对应的字段值赋值给变量*/<br/> &nbsp; &nbsp; &nbsp; &nbsp;FETCH cur INTO idval,taskIdval,groupIdval,emailval;<br/> &nbsp; &nbsp; &nbsp; &nbsp;IF done = 1 THEN<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LEAVE out_loop;<br/> &nbsp; &nbsp; &nbsp; &nbsp;END IF;<br/> &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;/*打开第二个游标*/<br/> &nbsp; &nbsp; &nbsp; &nbsp;OPEN cur2;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET done = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FETCH cur2 INTO infoId;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/*如果正式表不存在相同groupId and email记录，添加到正式表*/<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IF done = 1 THEN<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/*插入正式表*/<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;INSERT INTO `t_email_info` VALUES(idval,emailval,groupIdval,0,&#39;&#39;,NOW(),&#39;admin&#39;,NOW(),&#39;admin&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/*删除临时数据*/<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DELETE FROM `t_email_data_temp` WHERE id = idval;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/*计数器，每1000条才提交*/<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET counts = counts + 1;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/*发生异常，回滚*/<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IF err=1 THEN<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET isrollback=1;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ROLLBACK;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ELSE<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IF counts = 1000 THEN<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMIT;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/*达到1000条提交后，重置计数器*/<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SET counts=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END IF;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END IF;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ELSE<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/*已经存在相同记录，则删除该记录*/<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IF done=0 THEN<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DELETE FROM `t_email_data_temp` WHERE id = idval;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END IF;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END IF;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FETCH cur2 INTO infoId;<br/> &nbsp; &nbsp; &nbsp; &nbsp;CLOSE cur2;<br/> &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;/*控制外部的循环，该步骤不能缺少，否则只循环一次就结束了*/<br/> &nbsp; &nbsp; &nbsp; &nbsp;SET done=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp;END LOOP out_loop;<br/> &nbsp; &nbsp;CLOSE cur;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/*如果没有发生过回滚事件，则更新task状态*/<br/> &nbsp; &nbsp;/*如果回滚过，不更新task状态，下次执行任务的时候，会再次将剩余没有提交的数据进行添加到正式表*/<br/> &nbsp; &nbsp;IF isrollback=0 THEN<br/> &nbsp; &nbsp; &nbsp; &nbsp;UPDATE `t_email_task` t SET t.`if_finish` = 1 WHERE t.`id`=jobId;<br/> &nbsp; &nbsp;END IF;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;END$$<br/><br/>DELIMITER ;<br/></span></p></code></pre><p><br/></p>','2015-05-28 19:58:54','2015-05-28 19:58:54','5566e8f36ec09df596a730ed','1','存储自己曾经编写过的mysql存储过程，以后使用的时候可以作为参考。<br/>\n其中包括：存储过程、游标 (双重循环) 、事务控制。',1,NULL,1),('5567c9a36ec09df598a730ed','学习资源下载','<p><span style=\"font-size: 14px;\"><strong><span style=\"color: rgb(0, 176, 80);\">分享资源，分享给大家学习使用。</span></strong></span></p><p><span style=\"font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">[说明]：并不是所有资源都是原创，有的摘自网络。本人技术很一般，技术大牛请绕过^_^。有的资源比较大，耐心下载。</span></strong></span></p><p><br/></p><p><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"><strong>资源列表：</strong></span></p><p><br/></p><table><tbody><tr class=\"firstRow\"><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; text-decoration: underline; color: rgb(0, 0, 0);\" href=\"http://www.2b2b92b.com/resources/attached/file/SSO之CAS单点登录详细图文教程.zip\" title=\"SSO之CAS单点登录详细图文教程.zip\"><span style=\"color: rgb(0, 0, 0);\">SSO之CAS单点登录详细图文教程.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/apache+tomcat集群环境搭建图文教程.zip\" title=\"apache+tomcat集群环境搭建图文教程.zip\"><span style=\"color: rgb(0, 0, 0);\">apache+tomcat集群环境搭建图文教程.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" textvalue=\"MongoDB环境搭建与实例代码测试.rar\" title=\"MongoDB环境搭建与实例代码测试.rar\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/MongoDB环境搭建与实例代码测试.rar\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">MongoDB环境搭建与实例代码测试.rar</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" textvalue=\"spring_security3_详细配置(摘自网络).zip\" title=\"spring_security3_详细配置(摘自网络).zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/spring_security3_详细配置(摘自网络).zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">spring_security3_详细配置(摘自网络).zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" href=\"/resources/attached/file/断点+多线程下载实例.zip\" title=\"断点+多线程下载实例.zip\"><span style=\"color: rgb(0, 0, 0);\">断点+多线程下载实例.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/网页加载进度条-实例Demo.zip\" title=\"网页加载进度条-实例Demo.zip\"><span style=\"color: rgb(0, 0, 0);\">网页加载进度条-实例Demo.zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/微信JSAPI支付完整Demo.zip\" title=\"微信JSAPI支付完整Demo.zip\"><span style=\"color: rgb(0, 0, 0);\">微信JSAPI支付完整Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/支付宝PC支付完整Demo.zip\" title=\"支付宝PC支付完整Demo.zip\"><span style=\"color: rgb(0, 0, 0);\">支付宝PC支付完整Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size: 12px; color: rgb(0, 0, 0); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/springbatch批处理(完整Demo).zip\" title=\"springbatch批处理(完整Demo).zip\"><span style=\"color: rgb(0, 0, 0);\">springbatch批处理(完整Demo).zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"lucene基于本地磁盘的文件索引Demo.zip\" title=\"lucene基于本地磁盘的文件索引Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/lucene基于本地磁盘的文件索引Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">lucene基于本地磁盘的文件索引Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"lucene基于内存的检索Demo.zip\" title=\"lucene基于内存的检索Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/lucene基于内存的检索Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">lucene基于内存的检索Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"lucene索引——增删改查.zip\" title=\"lucene索引——增删改查.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/lucene索引——增删改查.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">lucene索引——增删改查.zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"Highcharts简单实例Demo.zip\" title=\"Highcharts简单实例Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/Highcharts简单实例Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">Highcharts简单实例Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"数据采集—基于百度文库的抓取Demo.zip\" title=\"数据采集—基于百度文库的抓取Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/数据采集—基于百度文库的抓取Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">数据采集—基于百度文库的抓取Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"基于dwr消息推送Demo.zip\" title=\"基于dwr消息推送Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/基于dwr消息推送Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">基于dwr消息推送Demo.zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"ActiveMQ消息监听处理入门Demo(Spring简单集成).zip\" title=\"ActiveMQ消息监听处理入门Demo(Spring简单集成).zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/ActiveMQ消息监听处理入门Demo(Spring简单集成).zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">ActiveMQ消息监听处理入门Demo(Spring简单集成).zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"WebSocket消息聊天室Demo.zip\" title=\"WebSocket消息聊天室Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/WebSocket消息聊天室Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">WebSocket消息聊天室Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"springsecurity权限控制Demo.zip\" title=\"springsecurity权限控制Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/springsecurity权限控制Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">springsecurity权限控制Demo.zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"DwrPush-模拟消息推送至所有当前在线的用户.zip\" title=\"DwrPush-模拟消息推送至所有当前在线的用户.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/DwrPush-模拟消息推送至所有当前在线的用户.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">DwrPush-模拟消息推送至所有当前在线的用户.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"dwrcomet-推送消息给指定用户Demo.zip\" title=\"dwrcomet-推送消息给指定用户Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/dwrcomet-推送消息给指定用户Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">dwrcomet-推送消息给指定用户Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"chatpush-在线聊天室(可选指定用户聊天).zip\" title=\"chatpush-在线聊天室(可选指定用户聊天).zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/chatpush-在线聊天室(可选指定用户聊天).zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">chatpush-在线聊天室(可选指定用户聊天).zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"easyui完整Demo-各种功能_布局.zip\" title=\"easyui完整Demo-各种功能_布局.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/easyui完整Demo-各种功能_布局.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">easyui完整Demo-各种功能_布局.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"dwz富客户端+springmvc+ibatis简单Demo.zip\" title=\"dwz富客户端+springmvc+ibatis简单Demo.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/dwz富客户端+springmvc+ibatis简单Demo.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">dwz富客户端+springmvc+ibatis简单Demo.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"springmvc+mybatis集成—干净框架(直接使用).zip\" title=\"springmvc+mybatis集成—干净框架(直接使用).zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/springmvc+mybatis集成—干净框架(直接使用).zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">springmvc+mybatis集成—干净框架(直接使用).zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"SpringActiveMQ消息发送与接收(WEB版)-入门实例.zip\" title=\"SpringActiveMQ消息发送与接收(WEB版)-入门实例.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/SpringActiveMQ消息发送与接收(WEB版)-入门实例.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">SpringActiveMQ消息发送与接收(WEB版)-入门实例.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"spring_activemq消息发送接收(最终版-非WEB访问).zip\" title=\"spring_activemq消息发送接收(最终版-非WEB访问).zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/spring_activemq消息发送接收(最终版-非WEB访问).zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">spring_activemq消息发送接收(最终版-非WEB访问).zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"jd-gui反编译jar_复制源码为java文件(自己写的工具).rar\" title=\"jd-gui反编译jar_复制源码为java文件(自己写的工具).rar\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/jd-gui反编译jar_复制源码为java文件(自己写的工具).rar\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">jd-gui反编译jar_复制源码为java文件(自己写的工具).rar</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"手机_日期时间控件.zip\" title=\"手机_日期时间控件.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/手机_日期时间控件.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">手机_日期时间控件.zip</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"jquery点击图片选中特效.rar\" title=\"jquery点击图片选中特效.rar\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/jquery点击图片选中特效.rar\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">jquery点击图片选中特效.rar</span></a></p></td><td style=\"word-break: break-all;\" valign=\"top\" width=\"374\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"JAVA之23种设计模式的完整实例代码.zip\" title=\"JAVA之23种设计模式的完整实例代码.zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/JAVA之23种设计模式的完整实例代码.zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">JAVA之23种设计模式的完整实例代码.zip</span></a></p></td></tr><tr><td style=\"word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"top\"><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\" textvalue=\"微信JSAPI支付完整Demo第二版(新增关闭订单、查询订单、查询退款、下载对账单、申请退款).zip\" title=\"微信JSAPI支付完整Demo第二版(新增关闭订单、查询订单、查询退款、下载对账单、申请退款).zip\" target=\"_self\" href=\"http://www.2b2b92b.com/resources/attached/file/微信JSAPI支付完整Demo第二版(新增关闭订单、查询订单、查询退款、下载对账单、申请退款).zip\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">微信JSAPI支付完整Demo第二版(新增关闭订单、查询订单、查询退款、下载对账单、申请退款).zip</span></a></p></td><td rowspan=\"1\" colspan=\"1\" valign=\"top\" style=\"word-break: break-all;\"><img src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\" style=\"line-height: 16px; white-space: normal; vertical-align: middle; margin-right: 2px;\"/><a href=\"http://www.2b2b92b.com/resources/attached/file/支付宝PC及时到账支付Demo-JAVA.zip\" target=\"_self\" title=\"支付宝PC及时到账支付Demo-JAVA.zip\" textvalue=\"支付宝PC及时到账支付Demo-JAVA.zip\" style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">支付宝PC及时到账支付Demo-JAVA.zip</span></a></td><td rowspan=\"1\" colspan=\"1\" valign=\"top\" style=\"word-break: break-all;\"><img src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\" style=\"white-space: normal; line-height: 16px; vertical-align: middle; margin-right: 2px;\"/><a href=\"http://www.2b2b92b.com/resources/attached/file/Java web项目：mybatis、springmvc、seajs、freemarker、分布式session、自定义taglib等.zip\" target=\"_self\" title=\"Java web项目：mybatis、springmvc、seajs、freemarker、分布式session、自定义taglib等.zip\" textvalue=\"Java web项目：mybatis、springmvc、seajs、freemarker、分布式session、自定义taglib等.zip\" style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">Java web项目：mybatis、springmvc、seajs、freemarker、分布式session、自定义taglib等.zip</span></a></td></tr><tr><td rowspan=\"1\" colspan=\"1\" valign=\"top\" style=\"word-break: break-all;\"><img src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\" style=\"white-space: normal; line-height: 16px; vertical-align: middle; margin-right: 2px;\"/><a href=\"http://www.2b2b92b.com/resources/attached/file/java线程异步：异步发送email、回调接口定义、其他异步线程demo.zip\" target=\"_self\" title=\"java线程异步：异步发送email、回调接口定义、其他异步线程demo.zip\" textvalue=\"java线程异步：异步发送email、回调接口定义、其他异步线程demo.zip\" style=\"text-decoration: underline; font-size: 12px; color: rgb(0, 0, 0);\"><span style=\"font-size: 12px; color: rgb(0, 0, 0);\">java线程异步：异步发送email、回调接口定义、其他异步线程demo.zip</span></a></td><td rowspan=\"1\" colspan=\"1\" valign=\"top\"><br/></td><td rowspan=\"1\" colspan=\"1\" valign=\"top\"><br/></td></tr></tbody></table><p><br/></p>','2015-05-29 10:06:27','2015-05-29 10:06:27','55631ee26ec09df591a730ed','1','分享自己曾经的研究成果，将demo、项目分享给大家学习使用。',1,NULL,1),('556802bb80689df543ea01f6','生成24位字符串ID__IdGenerator.java','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">此工具类用于生成24位字符串ID，唯一不重复。<br/>直接通过 IdGenerator.get() 获取。</span></strong></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><strong>源码如下</strong><strong>：<span style=\"color: rgb(0, 176, 80); font-size: 14px;\">(点击下载源码 - </span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"/resources/attached/file/IdGenerator.java\" title=\"IdGenerator.java\"><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">IdGenerator.java</span></a><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"><strong> )</strong></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><code><br/><p style=\"line-height: 1.5em;\">import java.net.NetworkInterface;<br/>import java.nio.ByteBuffer;<br/>import java.nio.ByteOrder;<br/>import java.util.Enumeration;<br/><br/>/**<br/> * 生成24位字符串ID<br/> * <br/> */<br/>public class IdGenerator implements Comparable&lt;IdGenerator&gt; {<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 调用该方法获取24位字符串ID<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String get() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return new IdGenerator().toString();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public IdGenerator() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;_time = _gentime;<br/> &nbsp; &nbsp; &nbsp; &nbsp;_machine = _genmachine;<br/> &nbsp; &nbsp; &nbsp; &nbsp;synchronized (_incLock) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_inc = _nextInc++;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;_new = true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public int hashCode() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return _inc;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public String toStringMongod() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;byte b[] = toByteArray();<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;StringBuilder buf = new StringBuilder(24);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; b.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int x = b[i] &amp; 0xFF;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String s = Integer.toHexString(x);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (s.length() == 1)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf.append(&quot;0&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf.append(s);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return buf.toString();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public byte[] toByteArray() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;byte b[] = new byte[12];<br/> &nbsp; &nbsp; &nbsp; &nbsp;ByteBuffer bb = ByteBuffer.wrap(b);<br/> &nbsp; &nbsp; &nbsp; &nbsp;bb.putInt(_inc);<br/> &nbsp; &nbsp; &nbsp; &nbsp;bb.putInt(_machine);<br/> &nbsp; &nbsp; &nbsp; &nbsp;bb.putInt(_time);<br/> &nbsp; &nbsp; &nbsp; &nbsp;reverse(b);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return b;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;static void reverse(byte[] b) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; b.length / 2; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;byte t = b[i];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b[i] = b[b.length - (i + 1)];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b[b.length - (i + 1)] = t;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;static String _pos(String s, int p) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return s.substring(p * 2, (p * 2) + 2);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public String toString() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return toStringMongod();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public int compareTo(IdGenerator id) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (id == null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return -1;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;long xx = id.getTime() - getTime();<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (xx &gt; 0)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return -1;<br/> &nbsp; &nbsp; &nbsp; &nbsp;else if (xx &lt; 0)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 1;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;int x = id._machine - _machine;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (x != 0)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return -x;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;x = id._inc - _inc;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (x != 0)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return -x;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return 0;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public int getMachine() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return _machine;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public long getTime() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;long z = _flip(_time);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return z * 1000;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public int getInc() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return _inc;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;final int _time;<br/> &nbsp; &nbsp;final int _machine;<br/> &nbsp; &nbsp;final int _inc;<br/><br/> &nbsp; &nbsp;boolean _new;<br/><br/> &nbsp; &nbsp;static int _flip(int x) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;byte b[] = new byte[4];<br/> &nbsp; &nbsp; &nbsp; &nbsp;ByteBuffer bb = ByteBuffer.wrap(b);<br/> &nbsp; &nbsp; &nbsp; &nbsp;bb.order(ByteOrder.LITTLE_ENDIAN);<br/> &nbsp; &nbsp; &nbsp; &nbsp;bb.putInt(x);<br/> &nbsp; &nbsp; &nbsp; &nbsp;bb.flip();<br/> &nbsp; &nbsp; &nbsp; &nbsp;bb.order(ByteOrder.BIG_ENDIAN);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return bb.getInt();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;private static int _nextInc = (new java.util.Random()).nextInt();<br/> &nbsp; &nbsp;private static final String _incLock = new String(&quot;IdGenerator._incLock&quot;);<br/><br/> &nbsp; &nbsp;private static int _gentime = _flip((int) (System.currentTimeMillis() / 1000));<br/><br/> &nbsp; &nbsp;static final Thread _timeFixer;<br/> &nbsp; &nbsp;private static final int _genmachine;<br/> &nbsp; &nbsp;static {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final int machinePiece;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StringBuilder sb = new StringBuilder();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Enumeration&lt;NetworkInterface&gt; e = NetworkInterface.getNetworkInterfaces();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (e.hasMoreElements()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NetworkInterface ni = e.nextElement();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(ni.toString());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;machinePiece = sb.toString().hashCode() &lt;&lt; 16;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final int processPiece = java.lang.management.ManagementFactory.getRuntimeMXBean().getName().hashCode() &amp; 0xFFFF;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_genmachine = machinePiece | processPiece;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (java.io.IOException ioe) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new RuntimeException(ioe);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;_timeFixer = new Thread(&quot;IdGenerator-TimeFixer&quot;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public void run() {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (true) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread.sleep(499);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (InterruptedException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_gentime = _flip((int) (System.currentTimeMillis() / 1000));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;};<br/> &nbsp; &nbsp; &nbsp; &nbsp;_timeFixer.setDaemon(true);<br/> &nbsp; &nbsp; &nbsp; &nbsp;_timeFixer.start();<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></p></code></code></pre><p><br/></p>','2015-05-29 14:10:03','2015-05-29 14:10:03','5568000980689df542ea01f6','1','此工具类用于生成24位字符串ID，唯一不重复。<br/>\n直接通过 IdGenerator.get() 获取。',1,NULL,1),('5568095f80689df544ea01f6','数组工具类 - ArrayUtil.java','<p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><strong><span style=\"color: rgb(0, 176, 80);\">数组工具类，提供数组、对象之间转换的方法。</span></strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：(<strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">点击下载</span> - </strong><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span><a style=\"text-decoration: underline; color: rgb(227, 108, 9); font-size: 14px;\" href=\"/resources/attached/file/ArrayUtil.java\" title=\"ArrayUtil.java\"><span style=\"font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">ArrayUtil.java</span></strong></span></a><span style=\"font-size: 14px;\"> 、</span><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span><a style=\"text-decoration: underline; color: rgb(227, 108, 9); font-size: 14px;\" href=\"/resources/attached/file/commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\"><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong>commons-lang-2.6.jar</strong></span></a><span style=\"font-size: 14px;\">)<br/></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><code><br/><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.lang.reflect.Array;<br/>import java.util.Collection;<br/>import java.util.Iterator;<br/><br/>import org.apache.commons.lang.StringUtils;<br/><br/>/**<br/> * 数组工具类<br/> * <br/> */<br/>public class ArrayUtil {<br/><br/> &nbsp; &nbsp;private transient static final String DEFAULT_JOIN_STR = &quot;,&quot;;<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 连接字符串 如：[1,2,3,4]，将会返回&quot;1,2,3,4&quot;<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param arr<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;an array of {@link java.lang.Object} objects.<br/> &nbsp; &nbsp; * @return a {@link java.lang.String} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final String join(final Object[] arr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return join(arr, DEFAULT_JOIN_STR);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 连接字符串 如: join([1,2,3,4],&quot;x&quot;]) 将会返回&quot;1x2x3x4&quot;<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param arr<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;an array of {@link java.lang.Object} objects.<br/> &nbsp; &nbsp; * @param joinStr<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return a {@link java.lang.String} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final String join(final Object[] arr, final String joinStr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (arr == null || arr.length &lt; 1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return StringUtils.EMPTY;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;final StringBuffer sb = new StringBuffer(String.valueOf(arr[0]));<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 1, len = arr.length; i &lt; len; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(StringUtils.isNotEmpty(joinStr) ? joinStr : StringUtils.EMPTY).append(String.valueOf(arr[i]));<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return sb.toString();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 集合转数组<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param collection<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;集合<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;类型<br/> &nbsp; &nbsp; * @return 数组<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;unchecked&quot;)<br/> &nbsp; &nbsp;public static final &lt;T&gt; T[] toArray(final Collection&lt;T&gt; collection, final Class&lt;T&gt; clazz) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (collection == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;final T[] arr = (T[]) Array.newInstance(clazz, collection.size());<br/> &nbsp; &nbsp; &nbsp; &nbsp;return collection.toArray(arr);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 集合转对象数组<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param collection<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;集合<br/> &nbsp; &nbsp; * @return 对象数组<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final Object[] toObjectArray(final Collection&lt;?&gt; collection) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (collection == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;final Object[] arr = (Object[]) Array.newInstance(Object.class, collection.size());<br/> &nbsp; &nbsp; &nbsp; &nbsp;int i = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (Iterator&lt;?&gt; it = collection.iterator(); it.hasNext();) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;arr[i++] = it.next();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return arr;<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></code></pre><p><br/></p>','2015-05-29 14:38:24','2015-05-29 14:38:24','5568000980689df542ea01f6','1','数组工具类，提供数组、对象之间转换的方法。',1,NULL,1),('55680dd580689df545ea01f6','Class类工具 - ClassUtils.java','<p><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">Class类工具，提供操作class类的方法。&lt;br/&gt;<br/>比如：获知类、方法上是否有注解，获取类注解，获取某package下所有class等。</span></strong></span></p><p><br/></p><p><span style=\"font-size: 14px;\">源码如下：<strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">(点击下载</span></strong> - </span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"/resources/attached/file/ClassUtils.java\" title=\"ClassUtils.java\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">ClassUtils.java</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> )</span></strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><br/></span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">import java.io.File;<br/>import java.io.FileFilter;<br/>import java.io.IOException;<br/>import java.lang.annotation.Annotation;<br/>import java.lang.reflect.Field;<br/>import java.lang.reflect.Method;<br/>import java.net.JarURLConnection;<br/>import java.net.URL;<br/>import java.net.URLDecoder;<br/>import java.util.ArrayList;<br/>import java.util.Enumeration;<br/>import java.util.LinkedHashSet;<br/>import java.util.List;<br/>import java.util.Set;<br/>import java.util.jar.JarEntry;<br/>import java.util.jar.JarFile;<br/><br/>/**<br/> * Class类工具<br/> * <br/> */<br/>public class ClassUtils {<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否有注解<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @param annotationClass<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @return a boolean.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean hasClassAnnotation(Class&lt;?&gt; clazz, Class&lt;? extends Annotation&gt; annotationClass) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return getClassAnnotation(clazz, annotationClass) != null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否有注解<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @param annotationClass<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @param fieldName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @throws cn.yicha.commons.exception.YichaException<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if any.<br/> &nbsp; &nbsp; * @return a boolean.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean hasFieldAnnotation(Class&lt;?&gt; clazz,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Class&lt;? extends Annotation&gt; annotationClass, String fieldName) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return getFieldAnnotation(clazz, annotationClass, fieldName) != null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否有注解<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @param annotationClass<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @param methodName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param paramType<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @throws cn.yicha.commons.exception.YichaException<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if any.<br/> &nbsp; &nbsp; * @return a boolean.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean hasMethodAnnotation(Class&lt;?&gt; clazz,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Class&lt;? extends Annotation&gt; annotationClass, String methodName, Class&lt;?&gt;... paramType) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return getMethodAnnotation(clazz, annotationClass, methodName, paramType) != null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取类注解<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;类<br/> &nbsp; &nbsp; * @param annotationClass<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;注解类<br/> &nbsp; &nbsp; * @return a A object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static &lt;A extends Annotation&gt; A getClassAnnotation(Class&lt;?&gt; clazz, Class&lt;A&gt; annotationClass) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return clazz.getAnnotation(annotationClass);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取类成员注解<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;类<br/> &nbsp; &nbsp; * @param annotationClass<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;注解类<br/> &nbsp; &nbsp; * @param fieldName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;成员属性名<br/> &nbsp; &nbsp; * @throws cn.yicha.commons.exception.YichaException<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if any.<br/> &nbsp; &nbsp; * @return a A object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static &lt;A extends Annotation&gt; A getFieldAnnotation(Class&lt;?&gt; clazz,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Class&lt;A&gt; annotationClass, String fieldName) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Field field = clazz.getDeclaredField(fieldName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (field == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;no such field[&quot; + fieldName + &quot;] in &quot; + clazz.getCanonicalName());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return field.getAnnotation(annotationClass);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (SecurityException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;access error: field[&quot; + fieldName + &quot;] in &quot; + clazz.getCanonicalName(), e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (NoSuchFieldException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;no such field[&quot; + fieldName + &quot;] in &quot; + clazz.getCanonicalName());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取类方法上的注解<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;类<br/> &nbsp; &nbsp; * @param annotationClass<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;注解类<br/> &nbsp; &nbsp; * @param methodName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;方法名<br/> &nbsp; &nbsp; * @param paramType<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;方法参数<br/> &nbsp; &nbsp; * @throws cn.yicha.commons.exception.YichaException<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if any.<br/> &nbsp; &nbsp; * @return a A object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static &lt;A extends Annotation&gt; A getMethodAnnotation(Class&lt;?&gt; clazz,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Class&lt;A&gt; annotationClass, String methodName, Class&lt;?&gt;... paramType)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method method = clazz.getDeclaredMethod(methodName, paramType);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (method == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;access error: method[&quot; + methodName + &quot;] in &quot; + clazz.getCanonicalName());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return method.getAnnotation(annotationClass);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (SecurityException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;access error: method[&quot; + methodName + &quot;] in &quot; + clazz.getCanonicalName(), e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (NoSuchMethodException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;no such method[&quot; + methodName + &quot;] in &quot; + clazz.getCanonicalName(), e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 从包package中获取所有的Class<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param pagekageName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;包名<br/> &nbsp; &nbsp; * @param recursive<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;是否递归<br/> &nbsp; &nbsp; * @return a {@link java.util.Set} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Set&lt;Class&lt;?&gt;&gt; getClasses(String pagekageName, boolean recursive) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 第一个class类的集合<br/> &nbsp; &nbsp; &nbsp; &nbsp;Set&lt;Class&lt;?&gt;&gt; classes = new LinkedHashSet&lt;Class&lt;?&gt;&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 获取包的名字 并进行替换<br/> &nbsp; &nbsp; &nbsp; &nbsp;String packageName = pagekageName;<br/> &nbsp; &nbsp; &nbsp; &nbsp;String packageDirName = packageName.replace(&#39;.&#39;, &#39;/&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 定义一个枚举的集合 并进行循环来处理这个目录下的things<br/> &nbsp; &nbsp; &nbsp; &nbsp;Enumeration&lt;URL&gt; dirs;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 循环迭代下去<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (dirs.hasMoreElements()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 获取下一个元素<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;URL url = dirs.nextElement();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 得到协议的名称<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String protocol = url.getProtocol();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果是以文件的形式保存在服务器上<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (&quot;file&quot;.equals(protocol)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 获取包的物理路径<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String filePath = URLDecoder.decode(url.getFile(), &quot;UTF-8&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 以文件的方式扫描整个包下的文件 并添加到集合中<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;findAndAddClassesInPackageByFile(packageName, filePath, recursive, classes);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (&quot;jar&quot;.equals(protocol)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果是jar包文件<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 定义一个JarFile<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JarFile jar;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 获取jar<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;jar = ((JarURLConnection) url.openConnection()).getJarFile();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 从此jar包 得到一个枚举类<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Enumeration&lt;JarEntry&gt; entries = jar.entries();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 同样的进行循环迭代<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (entries.hasMoreElements()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JarEntry entry = entries.nextElement();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String name = entry.getName();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果是以/开头的<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (name.charAt(0) == &#39;/&#39;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 获取后面的字符串<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;name = name.substring(1);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果前半部分和定义的包名相同<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (name.startsWith(packageDirName)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int idx = name.lastIndexOf(&#39;/&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果以&quot;/&quot;结尾 是一个包<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (idx != -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 获取包名 把&quot;/&quot;替换成&quot;.&quot;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;packageName = name.substring(0, idx)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.replace(&#39;/&#39;, &#39;.&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果可以迭代下去 并且是一个包<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((idx != -1) || recursive) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果是一个.class文件 而且不是目录<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (name.endsWith(&quot;.class&quot;) &amp;&amp; !entry.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 去掉后面的&quot;.class&quot; 获取真正的类名<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String className = name.substring(packageName.length() + 1, name.length() - 6);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 添加到classes<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;classes.add(Class.forName(packageName + &#39;.&#39; + className));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (ClassNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// .error(&quot;添加用户自定义视图类错误 找不到此类的.class文件&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log.error(&quot;在扫描用户定义视图时从jar包获取文件出错&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new RuntimeException(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return classes;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 以文件的形式来获取包下的所有Class<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param packageName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param packagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param recursive<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a boolean.<br/> &nbsp; &nbsp; * @param classes<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.util.Set} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void findAndAddClassesInPackageByFile(String packageName,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String packagePath, final boolean recursive, Set&lt;Class&lt;?&gt;&gt; classes) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 获取此包的目录 建立一个File<br/> &nbsp; &nbsp; &nbsp; &nbsp;File dir = new File(packagePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 如果不存在或者 也不是目录就直接返回<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!dir.exists() || !dir.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log.warn(&quot;用户定义包名 &quot; + packageName + &quot; 下没有任何文件&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 如果存在 就获取包下的所有文件 包括目录<br/> &nbsp; &nbsp; &nbsp; &nbsp;File[] dirfiles = dir.listFiles(new FileFilter() {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 自定义过滤规则 如果可以循环(包含子目录) 或则是以.class结尾的文件(编译好的java类文件)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public boolean accept(File file) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (recursive &amp;&amp; file.isDirectory()) || (file.getName().endsWith(&quot;.class&quot;));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;});<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 循环所有文件<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (File file : dirfiles) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果是目录 则继续扫描<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (file.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;findAndAddClassesInPackageByFile(packageName + &quot;.&quot; + file.getName(), file.getAbsolutePath(), recursive, classes);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果是java类文件 去掉后面的.class 只留下类名<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String className = file.getName().substring(0, file.getName().length() - 6);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 添加到集合中去<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;classes.add(Class.forName(packageName + &#39;.&#39; + className));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (ClassNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log.error(&quot;添加用户自定义视图类错误 找不到此类的.class文件&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * &lt;p&gt;<br/> &nbsp; &nbsp; * Description：给一个接口，返回这个接口同一个包下的所有实现类<br/> &nbsp; &nbsp; * &lt;/p&gt;<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param c<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @return a {@link java.util.List} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static List&lt;Class&lt;?&gt;&gt; getAllClassByInterface(Class&lt;?&gt; c) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;Class&lt;?&gt;&gt; returnClassList = new ArrayList&lt;Class&lt;?&gt;&gt;(); // 返回结果<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 如果不是一个接口，则不做处理<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!c.isInterface()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return returnClassList;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;String packageName = c.getPackage().getName(); // 获得当前的包名<br/> &nbsp; &nbsp; &nbsp; &nbsp;Set&lt;Class&lt;?&gt;&gt; allClass = getClasses(packageName, true); // 获得当前包下以及子包下的所有类<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 判断是否是同一个接口<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (Class&lt;?&gt; clazz : allClass) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (c.isAssignableFrom(clazz)) { // 判断是不是一个接口<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!c.equals(clazz)) { // 本身不加进去<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;returnClassList.add(clazz);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return returnClassList;<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></code></pre><p><br/></p>','2015-05-29 14:57:25','2015-05-29 14:57:25','5568000980689df542ea01f6','1','Class类工具，提供操作class类的方法。<br/>\n比如：获知类、方法上是否有注解，获取类注解，获取某package下所有class等。',1,NULL,1),('5568108280689df546ea01f6','Json工具类 - JsonUtils.java','<p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">Json工具类，提供Json与对象之间的转换。</span></strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：</span><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">(点击下载 - </span></strong><span style=\"color: rgb(227, 108, 9);\"><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span><a style=\"text-decoration: underline; font-size: 14px;\" href=\"/resources/attached/file/JsonUtils.java\" title=\"JsonUtils.java\"><span style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\"><strong><span style=\"color: rgb(227, 108, 9); font-size: 14px;\">JsonUtils.java</span></strong></span><strong><span style=\"font-size: 14px;\"></span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> 、 <span style=\"font-size: 14px; color: rgb(227, 108, 9);\"></span></span></strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"color: rgb(227, 108, 9); text-decoration: underline; font-size: 14px;\" href=\"/resources/attached/file/gson-2.2.4.jar\" title=\"gson-2.2.4.jar\"><span style=\"font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">gson-2.2.4.jar</span></strong></span></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><span style=\"font-size: 14px; color: rgb(227, 108, 9);\"></span> )</span></strong><span style=\"font-size: 14px;\"><br/></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><br/><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.lang.reflect.Type;<br/>import java.util.Map;<br/>import com.google.gson.Gson;<br/>import com.google.gson.GsonBuilder;<br/><br/>/**<br/> * Json工具类<br/> * <br/> */<br/>@SuppressWarnings(&quot;unchecked&quot;)<br/>public class JsonUtils {<br/><br/> &nbsp; &nbsp;private static Gson gson;<br/><br/> &nbsp; &nbsp;private JsonUtils() {<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;static {<br/> &nbsp; &nbsp; &nbsp; &nbsp;GsonBuilder gb = new GsonBuilder();<br/> &nbsp; &nbsp; &nbsp; &nbsp;gb.setDateFormat(&quot;yyyy-MM-dd HH:mm:ss&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gson = gb.create();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static final String toJson(Object obj) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gson.toJson(obj);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static final &lt;T&gt; T fromJson(final String json, Class&lt;T&gt; clazz) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gson.fromJson(json, clazz);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static final &lt;T&gt; T fromJson(final String json, Type t) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gson.fromJson(json, t);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static final Map&lt;String, Object&gt; fromJson(final String json) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return fromJson(json, Map.class);<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 15:08:50','2015-05-29 15:08:50','5568000980689df542ea01f6','1','Json工具类，提供Json与对象之间的转换。',1,NULL,1),('5568185780689df547ea01f6','对象工具类 - ObjectUtils.java','<p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(0, 176, 80);\"><strong>对象工具类，提供对象克隆、获取对象属性、类型判断、Map转换对象、对象转Map、设置对象属性等。</strong></span><br/><br/><br/>源码如下：<strong><span style=\"color: rgb(0, 176, 80);\">(点击下载 -&nbsp; </span></strong><strong><span style=\"color: rgb(0, 176, 80);\"></span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a textvalue=\"ObjectUtils.java\" title=\"ObjectUtils.java\" target=\"_self\" href=\"/resources/attached/file/ObjectUtils.java\"><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong>ObjectUtils.java</strong></span></a><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> 、</span></strong><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"></span></strong><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span><a textvalue=\"JsonUtils.java\" title=\"JsonUtils.java\" target=\"_self\" href=\"/resources/attached/file/JsonUtils.java\"><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong>JsonUtils.java</strong></span></a><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> 、</span></strong><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"></span></strong><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span><a textvalue=\"gson-2.2.4.jar\" title=\"gson-2.2.4.jar\" target=\"_self\" href=\"/resources/attached/file/gson-2.2.4.jar\"><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong>gson-2.2.4.jar</strong></span></a><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> 、</span></strong><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"></span></strong><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span><a textvalue=\"commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\" target=\"_self\" href=\"/resources/attached/file/commons-lang-2.6.jar\"><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong>commons-lang-2.6.jar</strong></span></a><span style=\"font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">)</span></strong><br/></span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.io.Serializable;<br/>import java.lang.reflect.Field;<br/>import java.lang.reflect.Method;<br/>import java.util.Map;<br/>import org.apache.commons.lang.SerializationUtils;<br/>import org.apache.commons.lang.StringUtils;<br/><br/>/**<br/> * 对象工具类<br/> * <br/> */<br/>public class ObjectUtils {<br/><br/> &nbsp; &nbsp;private static final Class&lt;?&gt;[] BASIC_NUMBER_CLASSES = new Class[] {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;short.class, int.class, long.class, float.class, double.class };<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 对象克隆<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param t<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a T object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;unchecked&quot;)<br/> &nbsp; &nbsp;public static final &lt;T&gt; T clone(T t) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (t == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (t instanceof Serializable) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (T) SerializationUtils.clone((Serializable) t);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;T result = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (t instanceof Cloneable) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result = (T) ObjectUtils.clone(t);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Throwable e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (result == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String json = JsonUtils.toJson(t);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result = (T) JsonUtils.fromJson(json, t.getClass());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return result;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 访问对象成员属性值值<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param obj<br/> &nbsp; &nbsp; * @param field<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; * @throws YichaException<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;rawtypes&quot;)<br/> &nbsp; &nbsp;private static final Object getFieldValue(Object obj, String field) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Object result = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (obj instanceof Map) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return ((Map) obj).get(field);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (obj == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;Method getterMethod = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getterMethod = obj.getClass().getMethod(&quot;get&quot; + StringUtils.capitalize(field));<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (getterMethod == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getterMethod = obj.getClass().getMethod(&quot;is&quot; + StringUtils.capitalize(field));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (getterMethod == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Field privateField;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;privateField = obj.getClass().getDeclaredField(field);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;privateField.setAccessible(true);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result = privateField.get(obj);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;field[&quot; + field + &quot;] doesn&#39;t exist.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result = getterMethod.invoke(obj);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return result;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取对象属性值<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param obj<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;被取值的对象<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;返回值的类型<br/> &nbsp; &nbsp; * @param path<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;格式:field1.field2.field3<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a T object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;unchecked&quot;)<br/> &nbsp; &nbsp;public static final &lt;T&gt; T getValue(Object obj, Class&lt;T&gt; clazz, String path) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Object o = getValue(obj, path);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return o == null ? null : (T) o;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * &lt;p&gt;<br/> &nbsp; &nbsp; * getValue.<br/> &nbsp; &nbsp; * &lt;/p&gt;<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param obj<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Object} object.<br/> &nbsp; &nbsp; * @param path<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return a {@link java.lang.Object} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final Object getValue(Object obj, String path) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (obj == null || StringUtils.isBlank(path)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;String[] arr = StringUtils.split(path, &quot;.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;Object o = obj;<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0, len = arr.length; i &lt; len; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final String field = StringUtils.strip(arr[i]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;o = getFieldValue(o, field);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;o = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return o;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 判断是否是数字类型<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param obj<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Object} object.<br/> &nbsp; &nbsp; * @return a boolean.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final boolean isNumberType(Object obj) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (obj == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new RuntimeException(&quot;object is null.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (obj instanceof Number) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (Class&lt;?&gt; clazz : BASIC_NUMBER_CLASSES) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (obj.getClass().equals(clazz)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 判断对象是否为零<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param obj<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Object} object.<br/> &nbsp; &nbsp; * @return a boolean.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final boolean isZero(Object obj) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isNumberType(obj)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;final String foo = String.valueOf(obj);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return StringUtils.equals(foo, &quot;0&quot;) || StringUtils.equals(foo, &quot;0.0&quot;);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * Map转换对象<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param map<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.util.Map} object.<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a T object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final &lt;T&gt; T fromMap(final Map&lt;String, Object&gt; map, Class&lt;T&gt; clazz) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return JsonUtils.fromJson(JsonUtils.toJson(map), clazz);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 对象转Map<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param object<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Object} object.<br/> &nbsp; &nbsp; * @return a {@link java.util.Map} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final Map&lt;String, Object&gt; toMap(final Object object) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return JsonUtils.fromJson(JsonUtils.toJson(object));<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 设置对象属性<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param object<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Object} object.<br/> &nbsp; &nbsp; * @param field<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param value<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @param paramType<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Class} object.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;rawtypes&quot;)<br/> &nbsp; &nbsp;public static final &lt;T&gt; void setValue(final Object object, final String field, final T value, final Class paramType) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method md = object.getClass().getMethod(&quot;set&quot; + StringUtils.capitalize(field), paramType);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (md != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;md.invoke(object, value);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Throwable e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new RuntimeException(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 设置对象属性<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param object<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.Object} object.<br/> &nbsp; &nbsp; * @param field<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param value<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final &lt;T&gt; void setValue(final Object object, final String field, final T value) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (Method method : object.getClass().getMethods()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (StringUtils.equals(method.getName(), &quot;set&quot; + StringUtils.capitalize(field))) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;method.invoke(object, value);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Throwable e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new RuntimeException(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></code></pre><p><br/></p>','2015-05-29 15:42:15','2015-05-29 15:42:15','5568000980689df542ea01f6','1','对象工具类，提供对象克隆、获取对象属性、类型判断、Map转换对象、对象转Map、设置对象属性等。',1,NULL,1),('55681a1680689df548ea01f6','日期工具类 - DateUtil.java','<p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"><strong>日期工具类，提供对日期的格式化和转换方法、获取区间日期、指定日期、每月最后一天等。</strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：<strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">(点击下载 -</span></strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\"><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span></span><a style=\"text-decoration: underline; color: rgb(227, 108, 9); font-size: 14px;\" href=\"/resources/attached/file/DateUtil.java\" title=\"DateUtil.java\"><span style=\"color: rgb(227, 108, 9); font-size: 14px;\"><strong>DateUtil.java</strong></span></a><span style=\"font-size: 14px;\"><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>、</strong></span><span style=\"font-size: 14px; color: rgb(227, 108, 9);\"><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span></span><a style=\"font-size: 14px; color: rgb(227, 108, 9); text-decoration: underline;\" textvalue=\"commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\" target=\"_self\" href=\"/resources/attached/file/commons-lang-2.6.jar\"><span style=\"font-size: 14px; color: rgb(227, 108, 9);\"><strong>commons-lang-2.6.jar</strong></span></a><span style=\"font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">&nbsp;</span></strong></span><span style=\"font-size: 14px;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">)</span></strong><br/></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.text.DateFormat;<br/>import java.text.ParseException;<br/>import java.text.SimpleDateFormat;<br/>import java.util.ArrayList;<br/>import java.util.Calendar;<br/>import java.util.Date;<br/>import java.util.GregorianCalendar;<br/>import java.util.List;<br/>import org.apache.commons.lang.StringUtils;<br/><br/>/**<br/> * 日期工具类<br/> * <br/> */<br/>public class DateUtil {<br/><br/> &nbsp; &nbsp;// 默认日期格式<br/> &nbsp; &nbsp;public static final String DATE_DEFAULT_FORMAT = &quot;yyyy-MM-dd&quot;;<br/><br/> &nbsp; &nbsp;// 默认时间格式<br/> &nbsp; &nbsp;public static final String DATETIME_DEFAULT_FORMAT = &quot;yyyy-MM-dd HH:mm:ss&quot;;<br/><br/> &nbsp; &nbsp;public static final String TIME_DEFAULT_FORMAT = &quot;HH:mm:ss&quot;;<br/><br/> &nbsp; &nbsp;// 日期格式化<br/> &nbsp; &nbsp;private static DateFormat dateFormat = null;<br/><br/> &nbsp; &nbsp;// 时间格式化<br/> &nbsp; &nbsp;private static DateFormat dateTimeFormat = null;<br/><br/> &nbsp; &nbsp;private static DateFormat timeFormat = null;<br/><br/> &nbsp; &nbsp;private static Calendar gregorianCalendar = null;<br/><br/> &nbsp; &nbsp;static {<br/> &nbsp; &nbsp; &nbsp; &nbsp;dateFormat = new SimpleDateFormat(DATE_DEFAULT_FORMAT);<br/> &nbsp; &nbsp; &nbsp; &nbsp;dateTimeFormat = new SimpleDateFormat(DATETIME_DEFAULT_FORMAT);<br/> &nbsp; &nbsp; &nbsp; &nbsp;timeFormat = new SimpleDateFormat(TIME_DEFAULT_FORMAT);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar = new GregorianCalendar();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 日期格式化yyyy-MM-dd<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date formatDate(String date, String format) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new SimpleDateFormat(format).parse(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (ParseException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 日期格式化yyyy-MM-dd<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String getDateFormat(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return dateFormat.format(date);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 日期格式化yyyy-MM-dd HH:mm:ss<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String getDateTimeFormat(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return dateTimeFormat.format(date);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 时间格式化<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return HH:mm:ss<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String getTimeFormat(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return timeFormat.format(date);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 日期格式化<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @param 格式类型<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String getDateFormat(Date date, String formatStr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (StringUtils.isNotBlank(formatStr)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new SimpleDateFormat(formatStr).format(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 日期格式化<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getDateFormat(String date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return dateFormat.parse(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (ParseException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 时间格式化<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getDateTimeFormat(String date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return dateTimeFormat.parse(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (ParseException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当前日期(yyyy-MM-dd)<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getNowDate() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return DateUtil.getDateFormat(dateFormat.format(new Date()));<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当前日期星期一日期<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return date<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getFirstDayOfWeek() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(new Date());<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek()); // Monday<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当前日期星期日日期<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return date<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getLastDayOfWeek() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(new Date());<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek() + 6); // Monday<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取日期星期一日期<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param 指定日期<br/> &nbsp; &nbsp; * @return date<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getFirstDayOfWeek(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (date == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek()); // Monday<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取日期星期一日期<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param 指定日期<br/> &nbsp; &nbsp; * @return date<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getLastDayOfWeek(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (date == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek() + 6); // Monday<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当前月的第一天<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return date<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getFirstDayOfMonth() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(new Date());<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当前月的最后一天<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getLastDayOfMonth() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(new Date());<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.add(Calendar.MONTH, 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.add(Calendar.DAY_OF_MONTH, -1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取指定月的第一天<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getFirstDayOfMonth(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取指定月的最后一天<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getLastDayOfMonth(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.add(Calendar.MONTH, 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.add(Calendar.DAY_OF_MONTH, -1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取日期前一天<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getDayBefore(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int day = gregorianCalendar.get(Calendar.DATE);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DATE, day - 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取日期后一天<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param date<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getDayAfter(Date date) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(date);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int day = gregorianCalendar.get(Calendar.DATE);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.set(Calendar.DATE, day + 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return gregorianCalendar.getTime();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当前年<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int getNowYear() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Calendar d = Calendar.getInstance();<br/> &nbsp; &nbsp; &nbsp; &nbsp;return d.get(Calendar.YEAR);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当前月份<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int getNowMonth() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Calendar d = Calendar.getInstance();<br/> &nbsp; &nbsp; &nbsp; &nbsp;return d.get(Calendar.MONTH) + 1;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取当月天数<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int getNowMonthDay() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Calendar d = Calendar.getInstance();<br/> &nbsp; &nbsp; &nbsp; &nbsp;return d.getActualMaximum(Calendar.DATE);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取时间段的每一天<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param 开始日期<br/> &nbsp; &nbsp; * @param 结算日期<br/> &nbsp; &nbsp; * @return 日期列表<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static List&lt;Date&gt; getEveryDay(Date startDate, Date endDate) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (startDate == null || endDate == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 格式化日期(yy-MM-dd)<br/> &nbsp; &nbsp; &nbsp; &nbsp;startDate = DateUtil.getDateFormat(DateUtil.getDateFormat(startDate));<br/> &nbsp; &nbsp; &nbsp; &nbsp;endDate = DateUtil.getDateFormat(DateUtil.getDateFormat(endDate));<br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;Date&gt; dates = new ArrayList&lt;Date&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.setTime(startDate);<br/> &nbsp; &nbsp; &nbsp; &nbsp;dates.add(gregorianCalendar.getTime());<br/> &nbsp; &nbsp; &nbsp; &nbsp;while (gregorianCalendar.getTime().compareTo(endDate) &lt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 加1天<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gregorianCalendar.add(Calendar.DAY_OF_MONTH, 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dates.add(gregorianCalendar.getTime());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return dates;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取提前多少个月<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param monty<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Date getFirstMonth(int monty) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Calendar c = Calendar.getInstance();<br/> &nbsp; &nbsp; &nbsp; &nbsp;c.add(Calendar.MONTH, -monty);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return c.getTime();<br/> &nbsp; &nbsp;}<br/>}<br/><br/></span></p></code></code></code></code></pre><p><br/></p>','2015-05-29 15:49:42','2015-05-29 15:49:42','5568000980689df542ea01f6','1','日期工具类，提供对日期的格式化和转换方法、获取区间日期、指定日期、每月最后一天等。',1,NULL,1),('556823ccfd369df5056480d5','加密工具类 - CryptoUtils.java','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">加密工具类，包含MD5,BASE64,SHA,CRC32的加密与解密方法。</span></strong></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>(点击下载&nbsp; - </strong></span></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"/resources/attached/file/CryptoUtils.java\" title=\"CryptoUtils.java\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">CryptoUtils.java</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">、</span></strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"/resources/attached/file/commons-io-2.4.jar\" title=\"commons-io-2.4.jar\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">commons-io-2.4.jar</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">、</span></strong><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"/resources/attached/file/commons-codec-1.9.jar\" title=\"commons-codec-1.9.jar\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">commons-codec-1.9.jar</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> )</span></strong><span style=\"font-size: 14px;\"><br/></span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import&nbsp;java.io.BufferedInputStream;<br/>import&nbsp;java.io.File;<br/>import&nbsp;java.io.FileInputStream;<br/>import&nbsp;java.io.FileNotFoundException;<br/>import&nbsp;java.io.IOException;<br/>import&nbsp;java.io.InputStream;<br/>import&nbsp;java.io.UnsupportedEncodingException;<br/>import&nbsp;java.net.URL;<br/>import&nbsp;java.util.zip.CRC32;<br/>import&nbsp;java.util.zip.CheckedInputStream;<br/>import&nbsp;org.apache.commons.codec.binary.Base64;<br/>import&nbsp;org.apache.commons.codec.digest.DigestUtils;<br/>import&nbsp;org.apache.commons.io.IOUtils;<br/><br/>/**<br/>&nbsp;*&nbsp;加密工具类，包含MD5,BASE64,SHA,CRC32<br/>&nbsp;*&nbsp;<br/>&nbsp;*/<br/>public&nbsp;class&nbsp;CryptoUtils&nbsp;{<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;final&nbsp;String&nbsp;DEFAULT_CHARSET&nbsp;=&nbsp;&quot;UTF-8&quot;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;MD5加密<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;bytes<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;an&nbsp;array&nbsp;of&nbsp;byte.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeMD5(final&nbsp;byte[]&nbsp;bytes)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;DigestUtils.md5Hex(bytes);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;MD5加密，默认UTF-8<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeMD5(final&nbsp;String&nbsp;str)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;encodeMD5(str,&nbsp;DEFAULT_CHARSET);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;MD5加密<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;charset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeMD5(final&nbsp;String&nbsp;str,&nbsp;final&nbsp;String&nbsp;charset)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(str&nbsp;==&nbsp;null)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;null;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;bytes&nbsp;=&nbsp;str.getBytes(charset);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;encodeMD5(bytes);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(UnsupportedEncodingException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;SHA加密<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;bytes<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;an&nbsp;array&nbsp;of&nbsp;byte.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeSHA(final&nbsp;byte[]&nbsp;bytes)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;DigestUtils.sha512Hex(bytes);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;SHA加密<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;charset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeSHA(final&nbsp;String&nbsp;str,&nbsp;final&nbsp;String&nbsp;charset)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(str&nbsp;==&nbsp;null)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;null;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;bytes&nbsp;=&nbsp;str.getBytes(charset);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;encodeSHA(bytes);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(UnsupportedEncodingException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;SHA加密,默认utf-8<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeSHA(final&nbsp;String&nbsp;str)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;encodeSHA(str,&nbsp;DEFAULT_CHARSET);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;BASE64加密<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;bytes<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;an&nbsp;array&nbsp;of&nbsp;byte.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeBASE64(final&nbsp;byte[]&nbsp;bytes)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;new&nbsp;String(Base64.encodeBase64String(bytes));<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;BASE64加密<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;charset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeBASE64(final&nbsp;String&nbsp;str,&nbsp;String&nbsp;charset)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(str&nbsp;==&nbsp;null)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;null;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;bytes&nbsp;=&nbsp;str.getBytes(charset);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;encodeBASE64(bytes);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(UnsupportedEncodingException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;BASE64加密,默认UTF-8<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;encodeBASE64(final&nbsp;String&nbsp;str)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;encodeBASE64(str,&nbsp;DEFAULT_CHARSET);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;BASE64解密,默认UTF-8<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;decodeBASE64(String&nbsp;str)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;decodeBASE64(str,&nbsp;DEFAULT_CHARSET);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;BASE64解密<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;charset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;字符编码<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;decodeBASE64(String&nbsp;str,&nbsp;String&nbsp;charset)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;bytes&nbsp;=&nbsp;str.getBytes(charset);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;new&nbsp;String(Base64.decodeBase64(bytes));<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(UnsupportedEncodingException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;CRC32字节校验<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;bytes<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;an&nbsp;array&nbsp;of&nbsp;byte.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;crc32(byte[]&nbsp;bytes)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CRC32&nbsp;crc32&nbsp;=&nbsp;new&nbsp;CRC32();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;crc32.update(bytes);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;Long.toHexString(crc32.getValue());<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;CRC32字符串校验<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;charset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;crc32(final&nbsp;String&nbsp;str,&nbsp;String&nbsp;charset)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;bytes&nbsp;=&nbsp;str.getBytes(charset);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;crc32(bytes);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(UnsupportedEncodingException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;CRC32字符串校验,默认UTF-8编码读取<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;crc32(final&nbsp;String&nbsp;str)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;crc32(str,&nbsp;DEFAULT_CHARSET);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;CRC32流校验<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;input<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.io.InputStream}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;crc32(InputStream&nbsp;input)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CRC32&nbsp;crc32&nbsp;=&nbsp;new&nbsp;CRC32();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckedInputStream&nbsp;checkInputStream&nbsp;=&nbsp;null;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;test&nbsp;=&nbsp;0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkInputStream&nbsp;=&nbsp;new&nbsp;CheckedInputStream(input,&nbsp;crc32);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test&nbsp;=&nbsp;checkInputStream.read();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;while&nbsp;(test&nbsp;!=&nbsp;-1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;Long.toHexString(crc32.getValue());<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;CRC32文件唯一校验<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;file<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.io.File}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;crc32(File&nbsp;file)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;input&nbsp;=&nbsp;null;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input&nbsp;=&nbsp;new&nbsp;BufferedInputStream(new&nbsp;FileInputStream(file));<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;crc32(input);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(FileNotFoundException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;finally&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IOUtils.closeQuietly(input);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;CRC32文件唯一校验<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;url<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;{@link&nbsp;java.net.URL}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;a&nbsp;{@link&nbsp;java.lang.String}&nbsp;object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;String&nbsp;crc32(URL&nbsp;url)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;input&nbsp;=&nbsp;null;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input&nbsp;=&nbsp;url.openStream();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;crc32(input);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(e);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;finally&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IOUtils.closeQuietly(input);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></pre><p><br/></p>','2015-05-29 16:31:07','2015-05-29 16:31:07','5568000980689df542ea01f6','1','加密工具类，包含MD5,BASE64,SHA,CRC32的加密与解密方法。',1,NULL,1),('5568257dfd369df5066480d5','文件夹工具类 - FolderUtils','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">文件夹工具类，提供创建完整路径的方法。</span></strong></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>(点击下载 -</strong></span></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/FolderUtils.java\" title=\"FolderUtils.java\"><strong><span style=\"color: rgb(227, 108, 9);\">FolderUtils.java</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> 、</span></strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-io-2.4.jar\" title=\"commons-io-2.4.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">commons-io-2.4.jar</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> )</span></strong><br/></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.io.File;<br/>import org.apache.commons.io.FilenameUtils;<br/><br/>/**<br/> * 文件夹工具<br/> * <br/> */<br/>public class FolderUtils {<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 创建完整路径<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param path<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void mkdirs(final String... path) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (String foo : path) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final String realPath = FilenameUtils.normalizeNoEndSeparator(foo, true);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final File folder = new File(realPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!folder.exists() || folder.isFile()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;folder.mkdirs();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 16:38:22','2015-05-29 16:38:22','5568000980689df542ea01f6','1','文件夹工具类，提供创建完整路径的方法。',1,NULL,1),('556827c5fd369df5076480d5','图片处理工具类 - ImageUtils.java','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">纯JAVA实现的图片处理工具类，提供图片的裁剪、压缩、获取尺寸、制作圆角等方法。</span></strong></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>(点击下载 -</strong></span></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"/resources/attached/file/ImageUtils.java\" title=\"ImageUtils.java\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">ImageUtils.java</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> 、</span></strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"http://www.2b2b92b.com/resources/attached/file/FolderUtils.java\" title=\"FolderUtils.java\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">FolderUtils.java</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> 、</span></strong><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-io-2.4.jar\" title=\"commons-io-2.4.jar\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">commons-io-2.4.jar</span></strong></a><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">、</span></strong><a style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\"><strong><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">commons-lang-2.6.jar</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">)</span></strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><br/></span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.awt.AlphaComposite;<br/>import java.awt.Color;<br/>import java.awt.Graphics2D;<br/>import java.awt.Image;<br/>import java.awt.RenderingHints;<br/>import java.awt.geom.RoundRectangle2D;<br/>import java.awt.image.BufferedImage;<br/>import java.io.BufferedInputStream;<br/>import java.io.BufferedOutputStream;<br/>import java.io.File;<br/>import java.io.FileInputStream;<br/>import java.io.FileNotFoundException;<br/>import java.io.FileOutputStream;<br/>import java.io.IOException;<br/>import java.io.InputStream;<br/>import java.io.OutputStream;<br/>import java.net.URL;<br/>import java.util.Iterator;<br/>import javax.imageio.IIOImage;<br/>import javax.imageio.ImageIO;<br/>import javax.imageio.ImageWriteParam;<br/>import javax.imageio.ImageWriter;<br/>import javax.imageio.stream.ImageOutputStream;<br/>import org.apache.commons.io.FilenameUtils;<br/>import org.apache.commons.io.IOUtils;<br/>import org.apache.commons.lang.StringUtils;<br/><br/>/**<br/> * 纯JAVA实现的图片处理工具类<br/> * <br/> */<br/>public class ImageUtils {<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取图片尺寸信息<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return [width, height]<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int[] getSizeInfo(String filePath) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return getSizeInfo(file);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取图片尺寸信息<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param url<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.net.URL} object.<br/> &nbsp; &nbsp; * @return [width,height]<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int[] getSizeInfo(URL url) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream input = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input = url.openStream();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return getSizeInfo(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取图片尺寸信息<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param file<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.File} object.<br/> &nbsp; &nbsp; * @return [width,height]<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int[] getSizeInfo(File file) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;file &quot; + file.getAbsolutePath() + &quot; doesn&#39;t exist.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedInputStream input = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input = new BufferedInputStream(new FileInputStream(file));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return getSizeInfo(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取图片尺寸<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param input<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.InputStream} object.<br/> &nbsp; &nbsp; * @return [width,height]<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int[] getSizeInfo(InputStream input) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage img = ImageIO.read(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int w = img.getWidth(null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int h = img.getHeight(null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new int[] { w, h };<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 重调图片尺寸<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param srcFilePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;原图路径<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的宽度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的高度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void resize(String srcFilePath, String destFile, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;resize(srcFilePath, destFile, width, height, -1, -1);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 重调图片尺寸<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param input<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.InputStream} object.<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.OutputStream} object.<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void resize(InputStream input, OutputStream output, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;resize(input, output, width, height, -1, -1);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 重调图片尺寸<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param input<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.InputStream} object.<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.OutputStream} object.<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param maxWidth<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param maxHeight<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void resize(InputStream input, OutputStream output,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int width, int height, int maxWidth, int maxHeight) throws Exception {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (width &lt; 1 &amp;&amp; height &lt; 1 &amp;&amp; maxWidth &lt; 1 &amp;&amp; maxHeight &lt; 1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.copy(input, output);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;resize error: &quot;, e);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage img = ImageIO.read(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boolean hasNotAlpha = !img.getColorModel().hasAlpha();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double w = img.getWidth(null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double h = img.getHeight(null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int toWidth;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int toHeight;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double rate = w / h;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (width &gt; 0 &amp;&amp; height &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rate = ((double) width) / ((double) height);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toWidth = width;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toHeight = height;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (width &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toWidth = width;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toHeight = (int) (toWidth / rate);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (height &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toHeight = height;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toWidth = (int) (toHeight * rate);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toWidth = ((Number) w).intValue();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toHeight = ((Number) h).intValue();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (maxWidth &gt; 0 &amp;&amp; toWidth &gt; maxWidth) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toWidth = maxWidth;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toHeight = (int) (toWidth / rate);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (maxHeight &gt; 0 &amp;&amp; toHeight &gt; maxHeight) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toHeight = maxHeight;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toWidth = (int) (toHeight * rate);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage tag = new BufferedImage(toWidth, toHeight, hasNotAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的 优先级比速度高 生成的图片质量比较好 但速度慢<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tag.getGraphics().drawImage(img.getScaledInstance(toWidth, toHeight, Image.SCALE_SMOOTH), 0, 0, null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageIO.write(tag, hasNotAlpha ? &quot;jpg&quot; : &quot;png&quot;, output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 重调图片尺寸<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param srcFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;原图路径<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的宽度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的高度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; * @param maxWidth<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;最大宽度，限制目标图片宽度，小于1则忽略此设置<br/> &nbsp; &nbsp; * @param maxHeight<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;最大高度，限制目标图片高度，小于1则忽略此设置<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void resize(String srcFile, String destFile, int width,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int height, int maxWidth, int maxHeight) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;resize(new File(srcFile), new File(destFile), width, height, maxWidth, maxHeight);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 重调图片尺寸<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param srcFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;原图路径<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的宽度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的高度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void resize(File srcFile, File destFile, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;resize(srcFile, destFile, width, height, -1, -1);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 重调图片尺寸<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param srcFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;原图路径<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的宽度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新的高度，小于1则忽略，按原图比例缩放<br/> &nbsp; &nbsp; * @param maxWidth<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;最大宽度，限制目标图片宽度，小于1则忽略此设置<br/> &nbsp; &nbsp; * @param maxHeight<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;最大高度，限制目标图片高度，小于1则忽略此设置<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void resize(File srcFile, File destFile, int width,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int height, int maxWidth, int maxHeight) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (destFile.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;destFile.delete();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(destFile.getParent());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream input = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;OutputStream output = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input = new BufferedInputStream(new FileInputStream(srcFile));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output = new FileOutputStream(destFile);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resize(input, output, width, height, maxWidth, maxHeight);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 裁剪图片<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param source<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param target<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param x<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param y<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param w<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param h<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void crop(String source, String target, int x, int y, int w, int h) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;crop(new File(source), new File(target), x, y, w, h);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 裁剪图片<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param source<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.File} object.<br/> &nbsp; &nbsp; * @param target<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.File} object.<br/> &nbsp; &nbsp; * @param x<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param y<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param w<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param h<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void crop(File source, File target, int x, int y, int w, int h) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;OutputStream output = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream input = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;String ext = FilenameUtils.getExtension(target.getName());<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input = new BufferedInputStream(new FileInputStream(source));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (target.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;target.delete();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(target.getParent());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output = new BufferedOutputStream(new FileOutputStream(target));<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;crop(input, output, x, y, w, h, StringUtils.equalsIgnoreCase(&quot;png&quot;, ext));<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 裁剪图片<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param x<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param y<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param w<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param h<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @param input<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.InputStream} object.<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.OutputStream} object.<br/> &nbsp; &nbsp; * @param isPNG<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a boolean.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void crop(InputStream input, OutputStream output, int x,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int y, int w, int h, boolean isPNG) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage srcImg = ImageIO.read(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int tmpWidth = srcImg.getWidth();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int tmpHeight = srcImg.getHeight();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int xx = Math.min(tmpWidth - 1, x);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int yy = Math.min(tmpHeight - 1, y);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int ww = w;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (xx + w &gt; tmpWidth) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ww = Math.max(1, tmpWidth - xx);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int hh = h;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (yy + h &gt; tmpHeight) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hh = Math.max(1, tmpHeight - yy);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage dest = srcImg.getSubimage(xx, yy, ww, hh);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage tag = new BufferedImage(w, h, isPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tag.getGraphics().drawImage(dest, 0, 0, null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageIO.write(tag, isPNG ? &quot;png&quot; : &quot;jpg&quot;, output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 压缩图片,PNG图片按JPG处理<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param input<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.InputStream} object.<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.OutputStream} object.<br/> &nbsp; &nbsp; * @param quality<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;图片质量0-1之间<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void optimize(InputStream input, OutputStream output, float quality) throws Exception {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;// create a BufferedImage as the result of decoding the supplied<br/> &nbsp; &nbsp; &nbsp; &nbsp;// InputStream<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage image;<br/> &nbsp; &nbsp; &nbsp; &nbsp;ImageOutputStream ios = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;ImageWriter writer = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image = ImageIO.read(input);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// get all image writers for JPG format<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Iterator&lt;ImageWriter&gt; writers = ImageIO.getImageWritersByFormatName(&quot;jpeg&quot;);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!writers.hasNext())<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new IllegalStateException(&quot;No writers found&quot;);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer = (ImageWriter) writers.next();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ios = ImageIO.createImageOutputStream(output);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.setOutput(ios);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageWriteParam param = writer.getDefaultWriteParam();<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// optimize to a given quality<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;param.setCompressionQuality(quality);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// appends a complete image stream containing a single image and<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// associated stream and image metadata and thumbnails to the output<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.write(null, new IIOImage(image, null, null), param);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ios != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ios.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.dispose();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 压缩图片<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param source<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param target<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param quality<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a float.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void optimize(String source, String target, float quality) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File fromFile = new File(source);<br/> &nbsp; &nbsp; &nbsp; &nbsp;File toFile = new File(target);<br/> &nbsp; &nbsp; &nbsp; &nbsp;optimize(fromFile, toFile, quality);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 压缩图片<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param source<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.File} object.<br/> &nbsp; &nbsp; * @param target<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.File} object.<br/> &nbsp; &nbsp; * @param quality<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;图片质量0-1之间<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void optimize(File source, File target, float quality) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (target.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;target.delete();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(target.getParent());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream is = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;OutputStream os = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is = new BufferedInputStream(new FileInputStream(source));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;os = new BufferedOutputStream(new FileOutputStream(target));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;optimize(is, os, quality);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(is);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(os);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 制作圆角<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param srcFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;原文件<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件<br/> &nbsp; &nbsp; * @param cornerRadius<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;角度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void makeRoundedCorner(File srcFile, File destFile, int cornerRadius) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream in = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;OutputStream out = null;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in = new BufferedInputStream(new FileInputStream(srcFile));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(destFile.getParentFile().getAbsolutePath());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out = new BufferedOutputStream(new FileOutputStream(destFile));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;makeRoundedCorner(in, out, cornerRadius);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(out);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(in);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 制作圆角<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param srcFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;原文件<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件<br/> &nbsp; &nbsp; * @param cornerRadius<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;角度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void makeRoundedCorner(String srcFile, String destFile, int cornerRadius) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;makeRoundedCorner(new File(srcFile), new File(destFile), cornerRadius);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 制作圆角<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param inputStream<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;原图输入流<br/> &nbsp; &nbsp; * @param outputStream<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标输出流<br/> &nbsp; &nbsp; * @param radius<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;角度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void makeRoundedCorner(final InputStream inputStream,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final OutputStream outputStream, final int radius) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage sourceImage = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage targetImage = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceImage = ImageIO.read(inputStream);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int w = sourceImage.getWidth();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int h = sourceImage.getHeight();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(w);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int cornerRadius = radius &lt; 1 ? w / 4 : radius;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Graphics2D g2 = targetImage.createGraphics();<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// This is what we want, but it only does hard-clipping, i.e.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// aliasing<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// g2.setClip(new RoundRectangle2D ...)<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// so instead fake soft-clipping by first drawing the desired clip<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// shape<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// in fully opaque white with antialiasing enabled...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g2.setComposite(AlphaComposite.Src);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g2.setColor(Color.WHITE);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius));<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ... then compositing the image on top,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// using the white shape from above as alpha source<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g2.setComposite(AlphaComposite.SrcAtop);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g2.drawImage(sourceImage, 0, 0, null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g2.dispose();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageIO.write(targetImage, &quot;png&quot;, outputStream);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 16:48:05','2015-05-29 16:48:05','5568000980689df542ea01f6','1','纯JAVA实现的图片处理工具类，提供图片的裁剪、压缩、获取尺寸、制作圆角等方法。',1,NULL,1),('55682980fd369df5086480d5','Cookie工具类 - CookieUtil.java','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">Cookie工具类，提供Cookie的创建、获取、删除方法。</span></strong></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>(点击下载 -</strong></span></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/CookieUtil.java\" title=\"CookieUtil.java\"><strong><span style=\"color: rgb(227, 108, 9);\">CookieUtil.java</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> )</span></strong><br/></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import javax.servlet.http.Cookie;<br/>import javax.servlet.http.HttpServletRequest;<br/>import javax.servlet.http.HttpServletResponse;<br/><br/>/**<br/> * Cookie工具类<br/> * <br/> */<br/>public class CookieUtil {<br/><br/> &nbsp; &nbsp;private CookieUtil() {<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 添加cookie<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param response<br/> &nbsp; &nbsp; * @param name<br/> &nbsp; &nbsp; * @param value<br/> &nbsp; &nbsp; * @param maxAge<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Cookie cookie = new Cookie(name, value);<br/> &nbsp; &nbsp; &nbsp; &nbsp;cookie.setPath(&quot;/&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (maxAge &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cookie.setMaxAge(maxAge);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;response.addCookie(cookie);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 删除cookie<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param response<br/> &nbsp; &nbsp; * @param name<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void removeCookie(HttpServletResponse response, String name) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Cookie uid = new Cookie(name, null);<br/> &nbsp; &nbsp; &nbsp; &nbsp;uid.setPath(&quot;/&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;uid.setMaxAge(0);<br/> &nbsp; &nbsp; &nbsp; &nbsp;response.addCookie(uid);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取cookie值<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param request<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String getUid(HttpServletRequest request,String cookieName) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Cookie cookies[] = request.getCookies();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (Cookie cookie : cookies) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (cookie.getName().equals(cookieName)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return cookie.getValue();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp;}<br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 16:55:29','2015-05-29 16:55:29','5568000980689df542ea01f6','1','Cookie工具类，提供Cookie的创建、获取、删除方法。',1,NULL,1),('55682be9fd369df5096480d5','拼音操作工具类 - PinyinUtil.java','<p style=\"line-height: 1.5em;\"><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">拼音操作工具类，提供字符串转换成拼音数组、汉字转换成拼音、取汉字的首字母等方法。</span></strong></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：</span><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">(点击下载 -</span></strong><strong><span style=\"font-size: 14px;\"></span></strong><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong></span><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/PinyinUtil.java\" title=\"PinyinUtil.java\"><strong><span style=\"color: rgb(227, 108, 9);\">PinyinUtil.java</span></strong></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>、</strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/pinyin4j-2.5.0.jar\" title=\"pinyin4j-2.5.0.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">pinyin4j-2.5.0.jar</span></strong></a><strong><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"> )</span></strong><br/></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import net.sourceforge.pinyin4j.PinyinHelper;<br/>import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;<br/>import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;<br/>import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;<br/>import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;<br/><br/>/**<br/> * 拼音操作工具类<br/> * <br/> */<br/>public class PinyinUtil {<br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将字符串转换成拼音数组<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String[] stringToPinyin(String src) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return stringToPinyin(src, false, null);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将字符串转换成拼音数组<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String[] stringToPinyin(String src, String separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return stringToPinyin(src, true, separator);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将字符串转换成拼音数组<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @param isPolyphone<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;是否查出多音字的所有拼音<br/> &nbsp; &nbsp; * @param separator<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;多音字拼音之间的分隔符<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String[] stringToPinyin(String src, boolean isPolyphone,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 判断字符串是否为空<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (&quot;&quot;.equals(src) || null == src) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;char[] srcChar = src.toCharArray();<br/> &nbsp; &nbsp; &nbsp; &nbsp;int srcCount = srcChar.length;<br/> &nbsp; &nbsp; &nbsp; &nbsp;String[] srcStr = new String[srcCount];<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; srcCount; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;srcStr[i] = charToPinyin(srcChar[i], isPolyphone, separator);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return srcStr;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将单个字符转换成拼音<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String charToPinyin(char src, boolean isPolyphone, String separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 创建汉语拼音处理类<br/> &nbsp; &nbsp; &nbsp; &nbsp;HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 输出设置，大小写，音标方式<br/> &nbsp; &nbsp; &nbsp; &nbsp;defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);<br/> &nbsp; &nbsp; &nbsp; &nbsp;defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;StringBuffer tempPinying = new StringBuffer();<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;// 如果是中文<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (src &gt; 128) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 转换得出结果<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String[] strs = PinyinHelper.toHanyuPinyinStringArray(src, defaultFormat);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 是否查出多音字，默认是查出多音字的第一个字符<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (isPolyphone &amp;&amp; null != separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; strs.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempPinying.append(strs[i]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (strs.length != (i + 1)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 多音字之间用特殊符号间隔起来<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempPinying.append(separator);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempPinying.append(strs[0]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (BadHanyuPinyinOutputFormatCombination e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempPinying.append(src);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return tempPinying.toString();<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static String hanziToPinyin(String hanzi) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return hanziToPinyin(hanzi, &quot; &quot;);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将汉字转换成拼音<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param hanzi<br/> &nbsp; &nbsp; * @param separator<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;deprecation&quot;)<br/> &nbsp; &nbsp;public static String hanziToPinyin(String hanzi, String separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 创建汉语拼音处理类<br/> &nbsp; &nbsp; &nbsp; &nbsp;HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 输出设置，大小写，音标方式<br/> &nbsp; &nbsp; &nbsp; &nbsp;defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);<br/> &nbsp; &nbsp; &nbsp; &nbsp;defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;String pinyingStr = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pinyingStr = PinyinHelper.toHanyuPinyinString(hanzi, defaultFormat, separator);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (BadHanyuPinyinOutputFormatCombination e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return pinyingStr;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将字符串数组转换成字符串<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * @param separator<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;各个字符串之间的分隔符<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String stringArrayToString(String[] str, String separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;StringBuffer sb = new StringBuffer();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; str.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(str[i]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (str.length != (i + 1)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(separator);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return sb.toString();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 简单的将各个字符数组之间连接起来<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String stringArrayToString(String[] str) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return stringArrayToString(str, &quot;&quot;);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将字符数组转换成字符串<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * @param separator<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;各个字符串之间的分隔符<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String charArrayToString(char[] ch, String separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;StringBuffer sb = new StringBuffer();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; ch.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(ch[i]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ch.length != (i + 1)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(separator);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return sb.toString();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将字符数组转换成字符串<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String charArrayToString(char[] ch) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return charArrayToString(ch, &quot; &quot;);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 取汉字的首字母<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @param isCapital<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;是否是大写<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static char[] getHeadByChar(char src, boolean isCapital) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 如果不是汉字直接返回<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (src &lt;= 128) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new char[] { src };<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 获取所有的拼音<br/> &nbsp; &nbsp; &nbsp; &nbsp;String[] pinyingStr = PinyinHelper.toHanyuPinyinStringArray(src);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 过滤中文符号<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (pinyingStr == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new char[] { src };<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 创建返回对象<br/> &nbsp; &nbsp; &nbsp; &nbsp;int polyphoneSize = pinyingStr.length;<br/> &nbsp; &nbsp; &nbsp; &nbsp;char[] headChars = new char[polyphoneSize];<br/> &nbsp; &nbsp; &nbsp; &nbsp;int i = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 截取首字符<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (String s : pinyingStr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;char headChar = s.charAt(0);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 首字母是否大写，默认是小写<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (isCapital) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;headChars[i] = Character.toUpperCase(headChar);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;headChars[i] = headChar;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i++;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return headChars;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 取汉字的首字母(默认是大写)<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static char[] getHeadByChar(char src) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return getHeadByChar(src, true);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 查找字符串首字母<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String[] getHeadByString(String src) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return getHeadByString(src, true);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 查找字符串首字母<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @param isCapital<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;是否大写<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String[] getHeadByString(String src, boolean isCapital) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return getHeadByString(src, isCapital, null);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 查找字符串首字母<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param src<br/> &nbsp; &nbsp; * @param isCapital<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;是否大写<br/> &nbsp; &nbsp; * @param separator<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;分隔符<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String[] getHeadByString(String src, boolean isCapital, String separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;char[] chars = src.toCharArray();<br/> &nbsp; &nbsp; &nbsp; &nbsp;String[] headString = new String[chars.length];<br/> &nbsp; &nbsp; &nbsp; &nbsp;int i = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (char ch : chars) {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;char[] chs = getHeadByChar(ch, isCapital);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StringBuffer sb = new StringBuffer();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (null != separator) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int j = 1;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (char ch1 : chs) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(ch1);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (j != chs.length) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(separator);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j++;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.append(chs[0]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;headString[i] = sb.toString();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i++;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return headString;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static String getPinyin(String hanzi) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return stringArrayToString(stringToPinyin(hanzi));<br/> &nbsp; &nbsp;}<br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 17:05:45','2015-05-29 17:05:45','5568000980689df542ea01f6','1','拼音操作工具类，提供字符串转换成拼音数组、汉字转换成拼音、取汉字的首字母等方法。',1,NULL,1),('55682e11fd369df50a6480d5','验证工具类 - ValidateUtils.java','<p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">验证工具类，提供验证email格式、是否ipv4、是否ipv6、是否中文、是否数字、正则表达式验证的方法。</span></strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">源码如下：<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>(点击下载 - </strong></span></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/ValidateUtils.java\" title=\"ValidateUtils.java\"><span style=\"color: rgb(227, 108, 9);\"><strong>ValidateUtils.java</strong></span></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong> 、</strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">commons-lang-2.6.jar</span></strong></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>、</strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/httpclient-4.3.3.jar\" title=\"httpclient-4.3.3.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">httpclient-4.3.3.jar</span></strong></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>)</strong></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.util.regex.Matcher;<br/>import java.util.regex.Pattern;<br/>import org.apache.commons.lang.StringUtils;<br/>import org.apache.http.conn.util.InetAddressUtils;<br/><br/>/**<br/> * 验证工具类<br/> * <br/> */<br/>public class ValidateUtils {<br/><br/> &nbsp; &nbsp;private static transient final String REGEX_IS_CHINESE = &quot;^[\\\\u4e00-\\\\u9fa5][\\\\u4e00-\\\\u9fa5]*[\\\\u4e00-\\\\u9fa5]$&quot;;<br/> &nbsp; &nbsp;private static transient final String REGEX_IS_EMAIL = &quot;^([a-z0-9A-Z]+[-_|\\\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\\\.)+[a-zA-Z]{2,}$&quot;;<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否email<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param email<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isEmail(String email) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return isMatch(email, REGEX_IS_EMAIL);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否email<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param email<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isNotEmail(String email) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return !isEmail(email);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否ipv4<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param ipv4<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isIPv4(String ipv4) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return InetAddressUtils.isIPv4Address(ipv4);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否ipv4<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param ipv4<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isNotIPv4(String ipv4) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return !isIPv4(ipv4);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否ipv6<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param ipv6<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isIPv6(String ipv6) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return InetAddressUtils.isIPv6Address(ipv6);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否ipv6<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param ipv6<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isNotIPv6(String ipv6) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return !isIPv6(ipv6);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否中文<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isChinese(String str) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return isMatch(str, REGEX_IS_CHINESE);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否数字<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isNumeric(String str) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return StringUtils.isNumeric(str);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 是否数字<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isNotNumeric(String str) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return !isNumeric(str);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 正则表达式验证<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param str<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param regex<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return 验证结果<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isMatch(String str, String regex) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;final Pattern pattern = Pattern.compile(regex);<br/> &nbsp; &nbsp; &nbsp; &nbsp;final Matcher matcher = pattern.matcher(str);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!matcher.find()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 17:14:57','2015-05-29 17:14:57','5568000980689df542ea01f6','1','验证工具类，提供验证email格式、是否ipv4、是否ipv6、是否中文、是否数字、正则表达式验证的方法。',1,NULL,1),('55683000fd369df50b6480d5','XML工具类 - XmlUtils.java','<p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">XML工具类，提供序列化XML、反序列化XML、获取指定节点的值的方法。</span></strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">源码如下：(点击下载 - </span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/XmlUtils.java\" title=\"XmlUtils.java\"><span style=\"color: rgb(227, 108, 9);\"><strong>XmlUtils.java</strong></span></a>、<strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/dom4j-1.6.1.jar\" title=\"dom4j-1.6.1.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">dom4j-1.6.1.jar</span></strong></a><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong>、<a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/xstream-1.4.7.jar\" title=\"xstream-1.4.7.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">xstream-1.4.7.jar</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"> )</span></strong></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import org.dom4j.Document;<br/>import org.dom4j.DocumentException;<br/>import org.dom4j.DocumentHelper;<br/>import org.dom4j.Element;<br/>import com.thoughtworks.xstream.XStream;<br/><br/>/**<br/> * XML工具类<br/> * <br/> */<br/>public class XmlUtils {<br/><br/> &nbsp; &nbsp;private final static String XML_DECLARATION = &quot;&lt;?xml version=\\&quot;1.0\\&quot; encoding=\\&quot;utf-8\\&quot;?&gt;&quot;;<br/><br/> &nbsp; &nbsp;private XmlUtils() {<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 序列化XML<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param obj<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static &lt;T&gt; String toXML(Object obj) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;XStream stream = getXStream();<br/> &nbsp; &nbsp; &nbsp; &nbsp;stream.processAnnotations(obj.getClass());<br/> &nbsp; &nbsp; &nbsp; &nbsp;return new StringBuffer(XML_DECLARATION).append(stream.toXML(obj)).toString();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 反序列化XML<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param xmlStr<br/> &nbsp; &nbsp; * @param clazz<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static &lt;T&gt; T fromXML(String xmlStr, Class&lt;T&gt; clazz) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;XStream stream = getXStream();<br/> &nbsp; &nbsp; &nbsp; &nbsp;stream.processAnnotations(clazz);<br/> &nbsp; &nbsp; &nbsp; &nbsp;Object obj = stream.fromXML(xmlStr);<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return clazz.cast(obj);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (ClassCastException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取指定节点的值<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param xpath<br/> &nbsp; &nbsp; * @param params<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String getNodeValue(String xpath, String dataStr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 将字符串转为xml<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Document document = DocumentHelper.parseText(dataStr);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 查找节点<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Element element = (Element) document.selectSingleNode(xpath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (element != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return element.getStringValue();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (DocumentException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return &quot;&quot;;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取Xstream实例<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static XStream getXStream() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return new XStream();<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 17:23:12','2015-05-29 17:23:12','5568000980689df542ea01f6','1','XML工具类，提供序列化XML、反序列化XML、获取指定节点的值的方法。',1,NULL,1),('55683310fd369df50c6480d5','压缩工具类 - ZipUtils.java','<p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">压缩工具类，提供压缩文件、解压文件的方法。</span></strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">源码如下：(点击下载 - </span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/ZipUtils.java\" title=\"ZipUtils.java\"><span style=\"color: rgb(227, 108, 9);\"><strong>ZipUtils.java</strong></span></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"> 、</span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/FolderUtils.java\" title=\"FolderUtils.java\"><strong><span style=\"color: rgb(227, 108, 9);\">FolderUtils.java</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/ant-1.7.0.jar\" title=\"ant-1.7.0.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">ant-1.7.0.jar</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-io-2.4.jar\" title=\"commons-io-2.4.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">commons-io-2.4.jar</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">commons-lang-2.6.jar</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">)</span></strong></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.io.BufferedInputStream;<br/>import java.io.BufferedOutputStream;<br/>import java.io.File;<br/>import java.io.FileInputStream;<br/>import java.io.FileOutputStream;<br/>import java.io.IOException;<br/>import java.io.InputStream;<br/>import java.util.Enumeration;<br/>import org.apache.commons.io.FilenameUtils;<br/>import org.apache.commons.io.IOUtils;<br/>import org.apache.commons.lang.ArrayUtils;<br/>import org.apache.commons.lang.StringUtils;<br/>import org.apache.tools.zip.ZipEntry;<br/>import org.apache.tools.zip.ZipFile;<br/>import org.apache.tools.zip.ZipOutputStream;<br/><br/>/**<br/> * 压缩工具类<br/> * <br/> */<br/>public class ZipUtils {<br/><br/> &nbsp; &nbsp;private static final String DEFAULT_CHARSET = &quot;UTF-8&quot;;<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 压缩文件夹<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param zipFileName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;打包后文件的名称，含路径<br/> &nbsp; &nbsp; * @param sourceFolder<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;需要打包的文件夹或者文件的路径<br/> &nbsp; &nbsp; * @param zipPathName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;打包目的文件夹名,为空则表示直接打包到根<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void zip(String zipFileName, String sourceFolder, String zipPathName) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;ZipOutputStream out = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File zipFile = new File(zipFileName);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(zipFile.getParent());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out = new ZipOutputStream(zipFile);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out.setEncoding(DEFAULT_CHARSET);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (StringUtils.isNotBlank(zipPathName)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zipPathName = FilenameUtils.normalizeNoEndSeparator(zipPathName, true) + &quot;/&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zipPathName = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zip(out, sourceFolder, zipPathName);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(out);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 压缩文件夹<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param zipFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param source<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void zip(String zipFile, String source) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(source);<br/> &nbsp; &nbsp; &nbsp; &nbsp;zip(zipFile, source, file.isFile() ? StringUtils.EMPTY : file.getName());<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 压缩文件夹<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param zipFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.File} object.<br/> &nbsp; &nbsp; * @param source<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.File} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void zip(File zipFile, File source) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;zip(zipFile.getAbsolutePath(), source.getAbsolutePath());<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;private static void zip(ZipOutputStream zos, String file, String pathName) throws IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file2zip = new File(file);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (file2zip.isFile()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zos.putNextEntry(new ZipEntry(pathName + file2zip.getName()));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.copy(new FileInputStream(file2zip.getAbsolutePath()), zos);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zos.flush();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zos.closeEntry();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File[] files = file2zip.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ArrayUtils.isNotEmpty(files)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (File f : files) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (f.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zip(zos, FilenameUtils.normalizeNoEndSeparator(f.getAbsolutePath(), true), <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FilenameUtils.normalizeNoEndSeparator(pathName + f.getName(), true) + &quot;/&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zos.putNextEntry(new ZipEntry(pathName + f.getName()));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.copy(new FileInputStream(f.getAbsolutePath()), zos);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zos.flush();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zos.closeEntry();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 解压<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param fromZipFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zip文件路径<br/> &nbsp; &nbsp; * @param unzipPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;解压路径<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;unchecked&quot;)<br/> &nbsp; &nbsp;public static final void unzip(String fromZipFile, String unzipPath) throws Exception {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;FileOutputStream fos = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream is = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;String path1 = StringUtils.EMPTY;<br/> &nbsp; &nbsp; &nbsp; &nbsp;String tempPath = StringUtils.EMPTY;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!new File(unzipPath).exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new File(unzipPath).mkdir();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;ZipFile zipFile = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zipFile = new ZipFile(fromZipFile, DEFAULT_CHARSET);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e1.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;File temp = new File(unzipPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;String strPath = temp.getAbsolutePath();<br/> &nbsp; &nbsp; &nbsp; &nbsp;Enumeration&lt;ZipEntry&gt; enu = zipFile.getEntries();<br/> &nbsp; &nbsp; &nbsp; &nbsp;ZipEntry zipEntry = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;while (enu.hasMoreElements()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zipEntry = (ZipEntry) enu.nextElement();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path1 = zipEntry.getName();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (zipEntry.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempPath = FilenameUtils.normalizeNoEndSeparator(strPath + File.separator + path1, true);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File dir = new File(tempPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dir.mkdirs();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;continue;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedInputStream bis = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedOutputStream bos = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is = zipFile.getInputStream(zipEntry);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bis = new BufferedInputStream(is);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path1 = zipEntry.getName();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempPath = FilenameUtils.normalizeNoEndSeparator(strPath + File.separator + path1, true);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(new File(tempPath).getParent());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fos = new FileOutputStream(tempPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bos = new BufferedOutputStream(fos);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.copy(bis, bos);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(bis);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(bos);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(is);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(fos);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/>}<br/><br/></span></p></code></pre><p><br/></p>','2015-05-29 17:36:16','2015-05-29 17:36:16','5568000980689df542ea01f6','1','压缩工具类，提供压缩文件、解压文件的方法。',1,NULL,1),('55683626fd369df50d6480d5','集合工具类 - CollectionUtil.java','<p><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">集合工具类，提供数组转LIST、数组转SET、合并集合、计算笛卡儿积等方法。</span></strong></span></p><p><br/></p><p><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">源码如下：(点击下载 -&nbsp; </span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/CollectionUtil.java\" title=\"CollectionUtil.java\"><span style=\"color: rgb(227, 108, 9);\"><strong>CollectionUtil.java</strong></span></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com:80/resources/attached/file/ArrayUtil.java\" title=\"ArrayUtil.java\"><strong><span style=\"color: rgb(227, 108, 9);\">ArrayUtil.java</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\"><span style=\"color: rgb(227, 108, 9);\"><strong>commons-lang-2.6.jar</strong></span></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/commons-collections4-4.0.jar\" title=\"commons-collections4-4.0.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">commons-collections4-4.0.jar</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">)</span></strong></span><br/></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">import java.util.ArrayList;<br/>import java.util.Arrays;<br/>import java.util.Collection;<br/>import java.util.LinkedHashSet;<br/>import java.util.List;<br/>import java.util.Set;<br/>import org.apache.commons.collections4.CollectionUtils;<br/>import org.apache.commons.lang.ArrayUtils;<br/><br/>/**<br/> * 集合工具类<br/> * <br/> */<br/>public class CollectionUtil {<br/><br/> &nbsp; &nbsp;private static transient final String DEFAULT_SPLIT_STR = &quot;,&quot;;<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 数组转列表<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param arr<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;an array of T objects.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a {@link java.util.List} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final &lt;T&gt; List&lt;T&gt; array2List(T[] arr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (ArrayUtils.isEmpty(arr)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return Arrays.asList(arr);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 数组转SET<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param arr<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;an array of T objects.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a {@link java.util.Set} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final &lt;T&gt; Set&lt;T&gt; array2Set(T[] arr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (ArrayUtils.isEmpty(arr)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return new LinkedHashSet&lt;T&gt;(Arrays.asList(arr));<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 合并集合<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param collections<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.util.Collection} object.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a {@link java.util.List} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;unchecked&quot;)<br/> &nbsp; &nbsp;public static final &lt;T&gt; List&lt;T&gt; collections2List(<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Collection&lt;T&gt;... collections) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (ArrayUtils.isEmpty(collections)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;final List&lt;T&gt; li = new ArrayList&lt;T&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (Collection&lt;T&gt; foo : collections) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (CollectionUtils.isNotEmpty(foo)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;li.addAll(foo);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return li;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 合并集合<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param collections<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.util.Collection} object.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a {@link java.util.Set} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;unchecked&quot;)<br/> &nbsp; &nbsp;public static final &lt;T&gt; Set&lt;T&gt; collections2Set(Collection&lt;T&gt;... collections) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (ArrayUtils.isEmpty(collections)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;final Set&lt;T&gt; set = new LinkedHashSet&lt;T&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (Collection&lt;T&gt; foo : collections) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (CollectionUtils.isNotEmpty(foo)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set.addAll(foo);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return set;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 拼接集合字符串<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param collection<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.util.Collection} object.<br/> &nbsp; &nbsp; * @param joinStr<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @return a {@link java.lang.String} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })<br/> &nbsp; &nbsp;public static final String join(final Collection collection, final String joinStr) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (CollectionUtils.isEmpty(collection)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (joinStr == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new IllegalArgumentException(&quot;join string is null.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;Object[] arr = ArrayUtil.toArray(collection, Object.class);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return ArrayUtil.join(arr, joinStr);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 拼接集合字符串<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param collection<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.util.Collection} object.<br/> &nbsp; &nbsp; * @return a {@link java.lang.String} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;rawtypes&quot;)<br/> &nbsp; &nbsp;public static final String join(final Collection collection) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return join(collection, DEFAULT_SPLIT_STR);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 计算笛卡儿积<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param crossArgs<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.util.List} object.<br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a T object.<br/> &nbsp; &nbsp; * @return a {@link java.util.List} object.<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static &lt;T&gt; List&lt;List&lt;T&gt;&gt; decartes(List&lt;List&lt;T&gt;&gt; crossArgs) {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;// 计算出笛卡尔积行数<br/> &nbsp; &nbsp; &nbsp; &nbsp;int rows = crossArgs.size() &gt; 0 ? 1 : 0;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;for (List&lt;T&gt; data : crossArgs) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rows *= data.size();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;// 笛卡尔积索引记录<br/> &nbsp; &nbsp; &nbsp; &nbsp;int[] record = new int[crossArgs.size()];<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;List&lt;T&gt;&gt; results = new ArrayList&lt;List&lt;T&gt;&gt;();<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;// 产生笛卡尔积<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; rows; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;T&gt; row = new ArrayList&lt;T&gt;();<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 生成笛卡尔积的每组数据<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int index = 0; index &lt; record.length; index++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;row.add(crossArgs.get(index).get(record[index]));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;results.add(row);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;crossRecord(crossArgs, record, crossArgs.size() - 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return results;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * @param sourceArgs<br/> &nbsp; &nbsp; * @param record<br/> &nbsp; &nbsp; * @param level<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;private static &lt;T&gt; void crossRecord(List&lt;List&lt;T&gt;&gt; sourceArgs, int[] record, int level) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;record[level] = record[level] + 1;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (record[level] &gt;= sourceArgs.get(level).size() &amp;&amp; level &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;record[level] = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;crossRecord(sourceArgs, record, level - 1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 从list中取得某段数据<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param &lt;T&gt;<br/> &nbsp; &nbsp; * @param datas<br/> &nbsp; &nbsp; * @param page<br/> &nbsp; &nbsp; * @param PAGESIZE<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static &lt;T&gt; List&lt;T&gt; getLimit(List&lt;T&gt; datas, int begin, int end) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;T&gt; objects = new ArrayList&lt;T&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (datas.size() &lt;= begin) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return objects;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;int temp = (datas.size() &gt; end) ? end : datas.size();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = begin; i &lt; temp; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;objects.add(datas.get(i));<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return objects;<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></code></pre><p><br/></p>','2015-05-29 17:49:26','2015-05-29 17:49:26','5568000980689df542ea01f6','1','集合工具类，提供数组转LIST、数组转SET、合并集合、计算笛卡儿积等方法。',1,NULL,1),('55683acbfd369df50e6480d5','二维码工具类 - QrcodeUtils.java','<p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">二维码工具类，提供多种生成二维码、解析二维码的方法，包括中间logo的二维码等方法。</span></strong></span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">源码如下：(点击下载 - </span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/QrcodeUtils.java\" title=\"QrcodeUtils.java\"><span style=\"color: rgb(227, 108, 9);\"><strong>QrcodeUtils.java</strong></span></a><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/>、<a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/MatrixToImageWriterEx.java\" title=\"MatrixToImageWriterEx.java\"><strong><span style=\"color: rgb(227, 108, 9);\">MatrixToImageWriterEx.java</span></strong></a><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/>、<a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/MatrixToLogoImageConfig.java\" title=\"MatrixToLogoImageConfig.java\"><strong><span style=\"color: rgb(227, 108, 9);\">MatrixToLogoImageConfig.java</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-io-2.4.jar\" title=\"commons-io-2.4.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">commons-io-2.4.jar</span></strong></a><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong>、<a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/commons-lang-2.6.jar\" title=\"commons-lang-2.6.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">commons-lang-2.6.jar</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">、</span></strong></span><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/slf4j-api-1.7.12.jar\" title=\"slf4j-api-1.7.12.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">slf4j-api-1.7.12.jar</span></strong></a><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong>、<a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/javase-3.1.0.jar\" title=\"javase-3.1.0.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">javase-3.1.0.jar</span></strong></a><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/>、<a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"/resources/attached/file/core-3.1.0.jar\" title=\"core-3.1.0.jar\"><strong><span style=\"color: rgb(227, 108, 9);\">core-3.1.0.jar</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"> 、</span></strong></span><strong><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/></strong><a style=\"font-size: 12px; color: rgb(227, 108, 9); text-decoration: underline;\" href=\"http://www.2b2b92b.com/resources/attached/file/FolderUtils.java\" title=\"FolderUtils.java\"><strong><span style=\"color: rgb(227, 108, 9);\">FolderUtils.java</span></strong></a><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">)</span></strong></span><br/></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(255, 0, 0);\"><strong><span style=\"font-size: 14px;\">QrcodeUtils.java 源码：</span></strong></span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.awt.Color;<br/>import java.awt.image.BufferedImage;<br/>import java.io.BufferedInputStream;<br/>import java.io.BufferedOutputStream;<br/>import java.io.File;<br/>import java.io.FileInputStream;<br/>import java.io.FileNotFoundException;<br/>import java.io.FileOutputStream;<br/>import java.io.IOException;<br/>import java.io.InputStream;<br/>import java.io.OutputStream;<br/>import java.net.URL;<br/>import java.util.HashMap;<br/>import java.util.Map;<br/>import java.util.UUID;<br/>import javax.imageio.ImageIO;<br/>import org.apache.commons.io.FilenameUtils;<br/>import org.apache.commons.io.IOUtils;<br/>import org.apache.commons.lang.ArrayUtils;<br/>import org.apache.commons.lang.StringUtils;<br/>import org.apache.commons.lang.SystemUtils;<br/>import org.slf4j.Logger;<br/>import org.slf4j.LoggerFactory;<br/>import com.google.zxing.BinaryBitmap;<br/>import com.google.zxing.DecodeHintType;<br/>import com.google.zxing.LuminanceSource;<br/>import com.google.zxing.MultiFormatReader;<br/>import com.google.zxing.Reader;<br/>import com.google.zxing.ReaderException;<br/>import com.google.zxing.client.j2se.BufferedImageLuminanceSource;<br/>import com.google.zxing.client.j2se.MatrixToImageWriter;<br/>import com.google.zxing.common.BitMatrix;<br/>import com.google.zxing.common.HybridBinarizer;<br/>import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;<br/><br/>/**<br/> * 二维码工具类<br/> * <br/> */<br/>public class QrcodeUtils {<br/><br/> &nbsp; &nbsp;private static final transient Logger LOGGER = LoggerFactory.getLogger(QrcodeUtils.class);<br/><br/> &nbsp; &nbsp;private static transient String DEFAULT_FORMAT = &quot;jpg&quot;;<br/> &nbsp; &nbsp;private static transient int DEFAULT_WIDTH = 200;<br/> &nbsp; &nbsp;private static transient int DEFAULT_HEIGHT = 200;<br/><br/> &nbsp; &nbsp;static {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final String[] foo = new String[] { &quot;240&quot;, &quot;240&quot; };<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final String format = &quot;jpg&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (StringUtils.isNotBlank(format)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEFAULT_FORMAT = StringUtils.strip(format).toLowerCase();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ArrayUtils.isNotEmpty(foo) &amp;&amp; foo.length == 2) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Integer tmpWidth = Integer.valueOf(foo[0]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Integer tmpHeight = Integer.valueOf(foo[1]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tmpWidth &gt; 0 &amp;&amp; tmpHeight &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEFAULT_WIDTH = tmpWidth;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEFAULT_HEIGHT = tmpHeight;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOGGER.warn(&quot;qrcode size must be lager than zero.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Throwable e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOGGER.warn(&quot;read default qrcode size config error: &quot;, e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码（无中间logo）<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出文件<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, File destFile) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, destFile, DEFAULT_WIDTH, DEFAULT_HEIGHT);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目的文件<br/> &nbsp; &nbsp; * @param logoFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中间logo文件<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final File destFile, final File logoFile) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, destFile, logoFile, DEFAULT_WIDTH, DEFAULT_HEIGHT);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目的文件<br/> &nbsp; &nbsp; * @param logoFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中间logo文件<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;高度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final File destFile,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final File logoFile, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(destFile.getParent());<br/> &nbsp; &nbsp; &nbsp; &nbsp;OutputStream output = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream input = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output = new BufferedOutputStream(new FileOutputStream(destFile));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (logoFile != null &amp;&amp; logoFile.exists() &amp;&amp; logoFile.isFile()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input = new BufferedInputStream(new FileInputStream(logoFile));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gen(content, output, input, width, height);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(output);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码（无中间logo）<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destFile<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出文件<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;高度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, File destFile, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;FolderUtils.mkdirs(destFile.getParent());<br/> &nbsp; &nbsp; &nbsp; &nbsp;OutputStream output = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output = new BufferedOutputStream(new FileOutputStream(destFile));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gen(content, output, width, height);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw e;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出流<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final OutputStream output) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, output, DEFAULT_WIDTH, DEFAULT_HEIGHT);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出流<br/> &nbsp; &nbsp; * @param logoInput<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中间logo输入流，为空时中间无logo<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final OutputStream output, final InputStream logoInput) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, output, logoInput, DEFAULT_WIDTH, DEFAULT_HEIGHT);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出流<br/> &nbsp; &nbsp; * @param logoInput<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中间logo输入流，为空时中间无logo<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;高度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final OutputStream output, final InputStream logoInput, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, output, logoInput, width, height, ErrorCorrectionLevel.M);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出流<br/> &nbsp; &nbsp; * @param logoInput<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中间logo输入流，为空时中间无logo<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;高度<br/> &nbsp; &nbsp; * @param errorCorrectionLevel<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;容错级别<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final OutputStream output, final InputStream logoInput, int width,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int height, ErrorCorrectionLevel errorCorrectionLevel) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (StringUtils.isEmpty(content)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new IllegalArgumentException(&quot;qr code content cannot be empty.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (output == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new IllegalArgumentException(&quot;qr code output stream cannot be null.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;final BitMatrix matrix = MatrixToImageWriterEx.createQRCode(content, width, height, errorCorrectionLevel);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (logoInput == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MatrixToImageWriter.writeToStream(matrix, DEFAULT_FORMAT, output);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;final MatrixToLogoImageConfig logoConfig = new MatrixToLogoImageConfig(Color.BLUE, 4);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;final String destPath = FilenameUtils.normalizeNoEndSeparator(SystemUtils.getJavaIoTmpDir()<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ File.separator + UUID.randomUUID().toString()<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ &quot;.tmp&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream tmpInput = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;final File destFile = new File(destPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MatrixToImageWriterEx.writeToFile(matrix, DEFAULT_FORMAT, destPath, logoInput, logoConfig);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tmpInput = new BufferedInputStream(new FileInputStream(destFile));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.copy(tmpInput, output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(tmpInput);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;destFile.delete();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param output<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出流<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;高度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final OutputStream output, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, output, null, width, height);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出文件路径<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final String destPath) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, destPath, DEFAULT_WIDTH, DEFAULT_HEIGHT);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;输出文件路径<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;高度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final String destPath, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, new File(destPath), width, height);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目的文件路径<br/> &nbsp; &nbsp; * @param logoPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中间logo文件路径<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final String destPath, final String logoPath) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, destPath, logoPath, DEFAULT_WIDTH, DEFAULT_HEIGHT);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文本内容<br/> &nbsp; &nbsp; * @param destPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目的文件路径<br/> &nbsp; &nbsp; * @param logoPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中间logo文件路径<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;高度<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final void gen(final String content, final String destPath,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final String logoPath, int width, int height) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File foo = new File(destPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;File bar = new File(logoPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;gen(content, foo, bar, width, height);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 解析二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param input<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码输入流<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final String parse(InputStream input) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Reader reader = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage image;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image = ImageIO.read(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (image == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;cannot read image from inputstream.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final LuminanceSource source = new BufferedImageLuminanceSource(image);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final Map&lt;DecodeHintType, String&gt; hints = new HashMap&lt;DecodeHintType, String&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hints.put(DecodeHintType.CHARACTER_SET, &quot;utf-8&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 解码设置编码方式为：utf-8，<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reader = new MultiFormatReader();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return reader.decode(bitmap, hints).getText();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;parse QR code error: &quot;, e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (ReaderException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;parse QR code error: &quot;, e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 解析二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param url<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码url<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final String parse(URL url) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream in = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in = url.openStream();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return parse(in);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;parse QR code error: &quot;, e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(in);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 解析二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param file<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码图片文件<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final String parse(File file) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream in = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in = new BufferedInputStream(new FileInputStream(file));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return parse(in);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;parse QR code error: &quot;, e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(in);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 解析二维码<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码图片文件路径<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static final String parse(String filePath) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream in = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in = new BufferedInputStream(new FileInputStream(filePath));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return parse(in);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new Exception(&quot;parse QR code error: &quot;, e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(in);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/>}<br/><br/></span></p></code></code></pre><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(255, 0, 0);\"><strong><span style=\"font-size: 14px;\">MatrixToImageWriterEx.java 源码：</span></strong></span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.awt.BasicStroke;<br/>import java.awt.Graphics2D;<br/>import java.awt.image.BufferedImage;<br/>import java.io.BufferedInputStream;<br/>import java.io.File;<br/>import java.io.FileInputStream;<br/>import java.io.IOException;<br/>import java.io.InputStream;<br/>import java.util.Hashtable;<br/>import javax.imageio.ImageIO;<br/>import org.apache.commons.io.IOUtils;<br/>import com.google.zxing.BarcodeFormat;<br/>import com.google.zxing.EncodeHintType;<br/>import com.google.zxing.MultiFormatWriter;<br/>import com.google.zxing.WriterException;<br/>import com.google.zxing.client.j2se.MatrixToImageConfig;<br/>import com.google.zxing.client.j2se.MatrixToImageWriter;<br/>import com.google.zxing.common.BitMatrix;<br/>import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;<br/><br/>class MatrixToImageWriterEx {<br/><br/> &nbsp; &nbsp;private static final MatrixToLogoImageConfig DEFAULT_CONFIG = new MatrixToLogoImageConfig();<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 根据内容生成二维码数据<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文字内容[为了信息安全性，一般都要先进行数据加密]<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片高度<br/> &nbsp; &nbsp; * @param errorCorrectionLevel<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;纠错等级<br/> &nbsp; &nbsp; * @return a {@link com.google.zxing.common.BitMatrix} object.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static BitMatrix createQRCode(String content, int width, int height,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ErrorCorrectionLevel errorCorrectionLevel) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;Hashtable&lt;EncodeHintType, Object&gt; hints = new Hashtable&lt;EncodeHintType, Object&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 设置字符编码<br/> &nbsp; &nbsp; &nbsp; &nbsp;hints.put(EncodeHintType.CHARACTER_SET, &quot;utf-8&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 指定纠错等级<br/> &nbsp; &nbsp; &nbsp; &nbsp;hints.put(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel);<br/> &nbsp; &nbsp; &nbsp; &nbsp;BitMatrix matrix = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (WriterException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return matrix;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 根据内容生成二维码数据<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码文字内容[为了信息安全性，一般都要先进行数据加密]<br/> &nbsp; &nbsp; * @param width<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片宽度<br/> &nbsp; &nbsp; * @param height<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片高度<br/> &nbsp; &nbsp; * @return a {@link com.google.zxing.common.BitMatrix} object.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static BitMatrix createQRCode(String content, int width, int height) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return createQRCode(content, width, height, ErrorCorrectionLevel.H);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 写入二维码、以及将照片logo写入二维码中<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param matrix<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;要写入的二维码<br/> &nbsp; &nbsp; * @param format<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片格式<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片保存路径<br/> &nbsp; &nbsp; * @param logoPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;logo路径<br/> &nbsp; &nbsp; * @throws java.io.IOException<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if any.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void writeToFile(BitMatrix matrix, String format,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String imagePath, String logoPath) throws IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream input = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input = new BufferedInputStream(new FileInputStream(logoPath));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeToFile(matrix, format, imagePath, input);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw e;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IOUtils.closeQuietly(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * &lt;p&gt;<br/> &nbsp; &nbsp; * writeToFile.<br/> &nbsp; &nbsp; * &lt;/p&gt;<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param matrix<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link com.google.zxing.common.BitMatrix} object.<br/> &nbsp; &nbsp; * @param format<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.lang.String} object.<br/> &nbsp; &nbsp; * @param logoInputStream<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.io.InputStream} object.<br/> &nbsp; &nbsp; * @throws java.io.IOException<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if any.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void writeToFile(BitMatrix matrix, String format,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String imagePath, InputStream logoInputStream) throws IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;MatrixToImageWriter.writeToPath(matrix, format, new File(imagePath).toPath(), new MatrixToImageConfig());<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 添加logo图片, 此处一定需要重新进行读取，而不能直接使用二维码的BufferedImage 对象<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage img = ImageIO.read(new File(imagePath));<br/> &nbsp; &nbsp; &nbsp; &nbsp;MatrixToImageWriterEx.overlapImage(img, format, imagePath, logoInputStream, DEFAULT_CONFIG);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 写入二维码、以及将照片logo写入二维码中<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param matrix<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;要写入的二维码<br/> &nbsp; &nbsp; * @param format<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片格式<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;二维码照片保存路径<br/> &nbsp; &nbsp; * @param logoPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;logo路径<br/> &nbsp; &nbsp; * @param logoConfig<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;logo配置对象<br/> &nbsp; &nbsp; * @throws java.io.IOException<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if any.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void writeToFile(BitMatrix matrix, String format, String imagePath, InputStream logoPath,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MatrixToLogoImageConfig logoConfig) throws IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;MatrixToImageWriter.writeToPath(matrix, format, new File(imagePath).toPath(), new MatrixToImageConfig());<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 添加logo图片, 此处一定需要重新进行读取，而不能直接使用二维码的BufferedImage 对象<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage img = ImageIO.read(new File(imagePath));<br/> &nbsp; &nbsp; &nbsp; &nbsp;MatrixToImageWriterEx.overlapImage(img, format, imagePath, logoPath, logoConfig);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将照片logo添加到二维码中间<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param image<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;生成的二维码照片对象<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;照片保存路径<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;照片保存路径<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;照片保存路径<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;照片保存路径<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;照片保存路径<br/> &nbsp; &nbsp; * @param imagePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;照片保存路径<br/> &nbsp; &nbsp; * @param logoInputStream<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;logo输入流<br/> &nbsp; &nbsp; * @param formate<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;照片格式<br/> &nbsp; &nbsp; * @param logoConfig<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link cn.yicha.commons.qrcode.MatrixToLogoImageConfig}<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;object.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void overlapImage(BufferedImage image, String formate,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String imagePath, InputStream logoInputStream,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MatrixToLogoImageConfig logoConfig) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage logo = ImageIO.read(logoInputStream);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Graphics2D g = image.createGraphics();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 考虑到logo照片贴到二维码中，建议大小不要超过二维码的1/5;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int width = image.getWidth() / logoConfig.getLogoPart();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int height = image.getHeight() / logoConfig.getLogoPart();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// logo起始位置，此目的是为logo居中显示<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int x = (image.getWidth() - width) / 2;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int y = (image.getHeight() - height) / 2;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 绘制图<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g.drawImage(logo, x, y, width, height, null);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 给logo画边框<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 构造一个具有指定线条宽度以及 cap 和 join 风格的默认值的实心 BasicStroke<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g.setStroke(new BasicStroke(logoConfig.getBorder()));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g.setColor(logoConfig.getBorderColor());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g.drawRect(x, y, width, height);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;g.dispose();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 写入logo照片到二维码<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageIO.write(image, formate, new File(imagePath));<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></p></code></code></pre><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(255, 0, 0);\"><strong><span style=\"font-size: 14px;\">MatrixToLogoImageConfig.java 源码：</span></strong></span></p><pre class=\"brush:java;toolbar:false\"><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">import java.awt.Color;<br/><br/>class MatrixToLogoImageConfig {<br/> &nbsp; &nbsp;// logo默认边框颜色<br/> &nbsp; &nbsp;/** Constant &lt;code&gt;DEFAULT_BORDERCOLOR&lt;/code&gt; */<br/> &nbsp; &nbsp;public static final Color DEFAULT_BORDERCOLOR = Color.RED;<br/> &nbsp; &nbsp;// logo默认边框宽度<br/> &nbsp; &nbsp;/** Constant &lt;code&gt;DEFAULT_BORDER=2&lt;/code&gt; */<br/> &nbsp; &nbsp;public static final int DEFAULT_BORDER = 2;<br/> &nbsp; &nbsp;// logo大小默认为照片的1/5<br/> &nbsp; &nbsp;/** Constant &lt;code&gt;DEFAULT_LOGOPART=5&lt;/code&gt; */<br/> &nbsp; &nbsp;public static final int DEFAULT_LOGOPART = 5;<br/><br/> &nbsp; &nbsp;private final int border = DEFAULT_BORDER;<br/> &nbsp; &nbsp;private final Color borderColor;<br/> &nbsp; &nbsp;private final int logoPart;<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * Creates a default config with on color {@link #BLACK} and off color<br/> &nbsp; &nbsp; * {@link #WHITE}, generating normal black-on-white barcodes.<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public MatrixToLogoImageConfig() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;this(DEFAULT_BORDERCOLOR, DEFAULT_LOGOPART);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * &lt;p&gt;<br/> &nbsp; &nbsp; * Constructor for MatrixToLogoImageConfig.<br/> &nbsp; &nbsp; * &lt;/p&gt;<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param borderColor<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a {@link java.awt.Color} object.<br/> &nbsp; &nbsp; * @param logoPart<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a int.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public MatrixToLogoImageConfig(Color borderColor, int logoPart) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;this.borderColor = borderColor;<br/> &nbsp; &nbsp; &nbsp; &nbsp;this.logoPart = logoPart;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * &lt;p&gt;<br/> &nbsp; &nbsp; * Getter for the field &lt;code&gt;borderColor&lt;/code&gt;.<br/> &nbsp; &nbsp; * &lt;/p&gt;<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return a {@link java.awt.Color} object.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public Color getBorderColor() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return borderColor;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * &lt;p&gt;<br/> &nbsp; &nbsp; * Getter for the field &lt;code&gt;border&lt;/code&gt;.<br/> &nbsp; &nbsp; * &lt;/p&gt;<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return a int.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public int getBorder() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return border;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * &lt;p&gt;<br/> &nbsp; &nbsp; * Getter for the field &lt;code&gt;logoPart&lt;/code&gt;.<br/> &nbsp; &nbsp; * &lt;/p&gt;<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return a int.<br/> &nbsp; &nbsp; * @since 0.0.7<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public int getLogoPart() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return logoPart;<br/> &nbsp; &nbsp;}<br/>}<br/><br/></span></p></code></code></pre><p><br/></p>','2015-05-29 18:09:15','2015-05-29 18:09:15','5568000980689df542ea01f6','1','二维码工具类，提供多种生成二维码、解析二维码的方法，包括中间logo的二维码等方法。',1,NULL,1),('556d261f78459df59370cfbb','JAVA多线程synchronized详解','<p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">Java语言的关键字，当它用来修饰一个方法或者一个代码块的时候，能够保证在同一时刻最多只有一个线程执行该段代码。</span></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">当两个并发线程访问同一个对象object中的这个synchronized(this)同步代码块时，一个时间内只能有一个线程得到执行。另一个线程必须等待当前线程执行完这个代码块以后才能执行该代码块。</span></p></li><li><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">然而，当一个线程访问object的一个synchronized(this)同步代码块时，另一个线程仍然可以访问该object中的非synchronized(this)同步代码块。</span></p></li><li><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">尤其关键的是，当一个线程访问object的一个synchronized(this)同步代码块时，其他线程对object中所有其它synchronized(this)同步代码块的访问将被阻塞。</span></p></li><li><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">第三个例子同样适用其它同步代码块。也就是说，当一个线程访问object的一个synchronized(this)同步代码块时，它就获得了这个object的对象锁。结果，其它线程对该object对象所有同步代码部分的访问都被暂时阻塞。</span></p></li><li><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">以上规则对其它对象锁同样适用.</span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\"></span></p></li></ul><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">举例说明(使用synchronized)：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">在编写一个类时，如果该类中的代码可能运行于多线程环境下，那么就要考虑同步的问题。在Java中内置了语言级的同步原语－－synchronized，这也大大简化了Java中多线程同步的使用。我们首先编写一个非常简单的多线程的程序，是模拟银行中的多个线程同时对同一个储蓄账户进行存款、取款操作的。<br/>在程序中我们使用了一个简化版本的Account类，代表了一个银行账户的信息。在主程序中我们首先生成了10000个线程，然后启动它们，每一个线程都对John的账户进行存100元，然后马上又取出100元。这样，对于John的账户来说，最终账户的余额应该是还是1000元才对。然而运行的结果却超出我们的想像，首先来看看我们的演示代码：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>/**<br/>&nbsp;*&nbsp;内部类<br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;模拟银行账户，测试多线程环境下的存钱、取钱<br/>&nbsp;*&nbsp;<br/>&nbsp;*&nbsp;作者:&nbsp;zhoubang&nbsp;<br/>&nbsp;*&nbsp;日期：2015年6月2日&nbsp;上午10:09:52<br/>&nbsp;*/<br/>class&nbsp;Account&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;/**账户金额*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;amount;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Account(float&nbsp;amount)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.amount&nbsp;=&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**存钱*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;deposit(float&nbsp;amt)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;tmp&nbsp;=&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;+=&nbsp;amt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**模拟其它处理所需要的时间，比如存完钱，后台系统更新数据库字段值等*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(100);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount&nbsp;=&nbsp;tmp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**取钱*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;withdraw(float&nbsp;amt)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;tmp&nbsp;=&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;-=&nbsp;amt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**模拟其它处理所需要的时间，比如存完钱，后台系统更新数据库字段值等*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(100);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount&nbsp;=&nbsp;tmp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;float&nbsp;getBalance()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/><br/>/**<br/>&nbsp;*&nbsp;账户存取金额&nbsp;&nbsp;多线程测试<br/>&nbsp;*&nbsp;<br/>&nbsp;*&nbsp;作者:&nbsp;zhoubang&nbsp;<br/>&nbsp;*&nbsp;日期：2015年6月2日&nbsp;上午10:05:05<br/>&nbsp;*/<br/>public&nbsp;class&nbsp;AccountTest&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;/**模拟多个线程同时操作该账户*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;int&nbsp;NUM_OF_THREAD&nbsp;=&nbsp;10000;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;Thread[]&nbsp;threads&nbsp;=&nbsp;new&nbsp;Thread[NUM_OF_THREAD];<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**为账户初始化1000元*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;Account&nbsp;acc&nbsp;=&nbsp;new&nbsp;Account(1000.0f);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**遍历线程，多个线程同时存取账户金额：每一个线程调用存钱的方法之后，立即调用取钱。*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;NUM_OF_THREAD;&nbsp;i++)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threads[i]&nbsp;=&nbsp;new&nbsp;Thread(new&nbsp;Runnable()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acc.deposit(100.0f);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acc.withdraw(100.0f);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threads[i].start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;主线程等待所有线程运行结束&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;NUM_OF_THREAD;&nbsp;i++)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threads[i].join();/**等待所有线程运行结束*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;所有线程执行完毕，最终的账户余额为：&quot;&nbsp;+&nbsp;acc.getBalance());<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">注意，上面在Account的deposit和withdraw方法中之所以要把对amount的运算使用一个临时变量首先存储，sleep一段时间，然后，再赋值给amount，是为了模拟真实运行时的情况。因为在真实系统中，账户信息肯定是存储在持久媒介中，比如RDBMS中，此处的睡眠的时间相当于比较耗时的数据库操作，最后把临时变量tmp的值赋值给amount相当于把amount的改动写入数据库中。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">运行AccountTest，结果如下（每一次结果都会不同）：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">所有线程执行完毕，最终的账户余额为：1500.0</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">所有线程执行完毕，最终的账户余额为：1700.0</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">所有线程执行完毕，最终的账户余额为：1300.0</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">。。。</span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">为什么会出现这样的问题？这就是多线程中的同步的问题。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">在我们的程序中，Account中的amount会同时被多个线程所访问，这就是一个竞争资源，通常称作竞态条件。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">对于这样的多个线程共享的资源我们必须进行同步，以避免一个线程的改动被另一个线程所覆盖。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">在我们这个程序中，Account中的amount是一个竞态条件，所以所有对amount的修改访问都要进行同步，</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">我们将deposit()和withdraw()方法进行同步，修改为：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>/**<br/>&nbsp;*&nbsp;内部类<br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;模拟银行账户，测试多线程环境下的存钱、取钱<br/>&nbsp;*&nbsp;<br/>&nbsp;*&nbsp;作者:&nbsp;zhoubang&nbsp;<br/>&nbsp;*&nbsp;日期：2015年6月2日&nbsp;上午10:09:52<br/>&nbsp;*/<br/>class&nbsp;Account&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;/**账户金额*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;amount;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Account(float&nbsp;amount)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.amount&nbsp;=&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**存钱*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;synchronized&nbsp;void&nbsp;deposit(float&nbsp;amt)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;tmp&nbsp;=&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;+=&nbsp;amt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**模拟其它处理所需要的时间，比如存完钱，后台系统更新数据库字段值等*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(100);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount&nbsp;=&nbsp;tmp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;/**取钱*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;synchronized&nbsp;void&nbsp;withdraw(float&nbsp;amt)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;tmp&nbsp;=&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;-=&nbsp;amt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**模拟其它处理所需要的时间，比如存完钱，后台系统更新数据库字段值等*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(100);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount&nbsp;=&nbsp;tmp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;float&nbsp;getBalance()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;amount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/><br/>/**<br/>&nbsp;*&nbsp;账户存取金额&nbsp;&nbsp;多线程测试<br/>&nbsp;*&nbsp;<br/>&nbsp;*&nbsp;作者:&nbsp;zhoubang&nbsp;<br/>&nbsp;*&nbsp;日期：2015年6月2日&nbsp;上午10:05:05<br/>&nbsp;*/<br/>public&nbsp;class&nbsp;AccountTest&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;/**模拟多个线程同时操作该账户*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;int&nbsp;NUM_OF_THREAD&nbsp;=&nbsp;10000;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;Thread[]&nbsp;threads&nbsp;=&nbsp;new&nbsp;Thread[NUM_OF_THREAD];<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**为账户初始化1000元*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;Account&nbsp;acc&nbsp;=&nbsp;new&nbsp;Account(1000.0f);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**遍历线程，多个线程同时存取账户金额：每一个线程调用存钱的方法之后，立即调用取钱。*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;NUM_OF_THREAD;&nbsp;i++)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threads[i]&nbsp;=&nbsp;new&nbsp;Thread(new&nbsp;Runnable()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acc.deposit(100.0f);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acc.withdraw(100.0f);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threads[i].start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;主线程等待所有线程运行结束&nbsp;*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;NUM_OF_THREAD;&nbsp;i++)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threads[i].join();/**等待所有线程运行结束*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;e)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;所有线程执行完毕，最终的账户余额为：&quot;&nbsp;+&nbsp;acc.getBalance());<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">此时，再运行，我们就能够得到正确的结果了。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">Account中的getBalance()也访问了amount，为什么不对getBalance()同步呢？</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">因为getBalance()并不会修改amount的值，所以，同时多个线程对它访问不会造成数据的混乱。</span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">同步加锁的是对象，而不是代码。<br/>因此，如果你的类中有一个同步方法，这个方法可以被两个不同的线程同时执行，只要每个线程自己创建一个的该类的实例即可。<br/><br/>参考下面的代码：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>class&nbsp;Foo&nbsp;extends&nbsp;Thread&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;int&nbsp;val;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Foo(int&nbsp;v)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;=&nbsp;v;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;synchronized&nbsp;void&nbsp;printVal(int&nbsp;v)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(true)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(v);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printVal(val);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/><br/>class&nbsp;SyncTest&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String&nbsp;args[])&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Foo&nbsp;f1&nbsp;=&nbsp;new&nbsp;Foo(1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f1.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Foo&nbsp;f2&nbsp;=&nbsp;new&nbsp;Foo(3);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f2.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">运行SyncTest产生的输出是1和3交叉的。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">如果printVal是断面，你看到的输出只能是1或者只能是3而不能是两者同时出现。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">程序运行的结果证明两个线程都在并发的执行printVal方法，即使该方法是同步的并且由于是一个无限循环而没有终止。</span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">类的同步：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">要实现真正的断面，你必须同步一个全局对象或者对类进行同步。下面的代码给出了一个这样的范例。</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>class&nbsp;Foo&nbsp;extends&nbsp;Thread&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;int&nbsp;val;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Foo(int&nbsp;v)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;=&nbsp;v;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;printVal(int&nbsp;v)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronized(Foo.class){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(true)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(v);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printVal(val);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">上面的类不再对个别的类实例同步而是对类进行同步。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">对于类Foo而言，它只有唯一的类定义，两个线程在相同的锁上同步，因此只有一个线程可以执行printVal方法。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">这个代码也可以通过对公共对象加锁。例如给Foo添加一个静态成员。两个方法都可以同步这个对象而达到线程安全。</span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">下面给出一个参考实现，给出同步公共对象的两种通常方法：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">1、</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>class&nbsp;Foo&nbsp;extends&nbsp;Thread&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;int&nbsp;val;<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;Object&nbsp;lock&nbsp;=&nbsp;new&nbsp;Object();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Foo(int&nbsp;v)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;=&nbsp;v;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;printVal(int&nbsp;v)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronized&nbsp;(lock)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(true)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(v);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printVal(val);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">上面的这个例子比原文给出的例子要好一些，因为原文中的加锁是针对类定义的，一个类只能有一个类定义，而同步的一般原理是应该尽量减小同步的粒度以到达更好的性能。这里给出的范例的同步粒度比原文的要小。</span></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">2、</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>class&nbsp;Foo&nbsp;extends&nbsp;Thread&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;String&nbsp;name;<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;String&nbsp;val;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Foo(String&nbsp;name,&nbsp;String&nbsp;v)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.name&nbsp;=&nbsp;name;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;=&nbsp;v;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;printVal()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronized&nbsp;(val)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(true)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(name&nbsp;+&nbsp;val);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printVal();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">public&nbsp;class&nbsp;SyncMethodTest&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String&nbsp;args[])&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Foo&nbsp;f1&nbsp;=&nbsp;new&nbsp;Foo(&quot;Foo&nbsp;1:&quot;,&nbsp;&quot;printVal&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f1.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Foo&nbsp;f2&nbsp;=&nbsp;new&nbsp;Foo(&quot;Foo&nbsp;2:&quot;,&nbsp;&quot;printVal&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f2.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">上面这个代码需要进行一些额外的说明，因为JVM有一种优化机制，因为String类型的对象是不可变的，因此当你使用&quot;&quot;的形式引用字符串时，如果JVM发现内存已经有一个这样的对象，那么它就使用那个对象而不再生成一个新的String对象，这样是为了减小内存的使用。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">上面的main方法其实等同于：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">public&nbsp;static&nbsp;void&nbsp;main(String&nbsp;args[])&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;value=&quot;printVal&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Foo&nbsp;f1&nbsp;=&nbsp;new&nbsp;Foo(&quot;Foo&nbsp;1:&quot;,value);&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;f1.start();&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Foo&nbsp;f2&nbsp;=&nbsp;new&nbsp;Foo(&quot;Foo&nbsp;2:&quot;,value);<br/>&nbsp;&nbsp;&nbsp;&nbsp;f2.start();&nbsp;<br/>}<br/></span></p></code></code></code></p></code></pre><p><br/></p><p><br/></p><p><br/></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">下面开始举第二个例子：</span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;一、当两个并发线程访问同一个对象object中的这个synchronized(this)同步代码块时，一个时间内只能有一个线程得到执行。</span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">另一个线程必须等待当前线程执行完这个代码块以后才能执行该代码块。</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>public&nbsp;class&nbsp;Thread1&nbsp;implements&nbsp;Runnable&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronized&nbsp;(this)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;5;&nbsp;i++)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;synchronized&nbsp;loop&nbsp;&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread1&nbsp;t1&nbsp;=&nbsp;new&nbsp;Thread1();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;ta&nbsp;=&nbsp;new&nbsp;Thread(t1,&nbsp;&quot;A&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;tb&nbsp;=&nbsp;new&nbsp;Thread(t1,&nbsp;&quot;B&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ta.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tb.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">结果：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; A synchronized loop 0&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; A synchronized loop 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; A synchronized loop 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; A synchronized loop 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; A synchronized loop 4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; B synchronized loop 0&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; B synchronized loop 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; B synchronized loop 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; B synchronized loop 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; B synchronized loop 4</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">二、然而，当一个线程访问object的一个synchronized(this)同步代码块时，另一个线程仍然可以访问该object中的非synchronized(this)同步代码块。</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>public&nbsp;class&nbsp;Thread2&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;m4t1()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronized&nbsp;(this)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i&nbsp;=&nbsp;5;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i--&nbsp;&gt;&nbsp;0)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;:&nbsp;&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(500);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;ie)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;m4t2()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i&nbsp;=&nbsp;5;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i--&nbsp;&gt;&nbsp;0)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;:&nbsp;&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(500);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;ie)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;Thread2&nbsp;myt2&nbsp;=&nbsp;new&nbsp;Thread2();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;t1&nbsp;=&nbsp;new&nbsp;Thread(new&nbsp;Runnable()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myt2.m4t1();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&quot;t1&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;t2&nbsp;=&nbsp;new&nbsp;Thread(new&nbsp;Runnable()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myt2.m4t2();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&quot;t2&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t1.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t2.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">结果：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 0&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 0</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">三、尤其关键的是，当一个线程访问object的一个synchronized(this)同步代码块时，其他线程对object中所有其它synchronized(this)同步代码块的访问将被阻塞。</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;修改Thread2.m4t2()方法：<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;m4t2()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronized&nbsp;(this)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i&nbsp;=&nbsp;5;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i--&nbsp;&gt;&nbsp;0)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;:&nbsp;&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(500);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;ie)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">结果：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 0&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 0</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">四、第三个例子同样适用其它同步代码块。也就是说，当一个线程访问object的一个synchronized(this)同步代码块时，它就获得了这个object的对象锁。结果，其它线程对该object对象所有同步代码部分的访问都被暂时阻塞。</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;修改Thread2.m4t2()方法如下：<br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;synchronized&nbsp;void&nbsp;m4t2()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i&nbsp;=&nbsp;5;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i--&nbsp;&gt;&nbsp;0)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;:&nbsp;&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(500);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;ie)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">结果：</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : 0&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : 0</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">五、以上规则对其它对象锁同样适用:<br/></span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package&nbsp;com.zb.notify;<br/><br/>public&nbsp;class&nbsp;Thread3&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;class&nbsp;Inner&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;m4t1()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i&nbsp;=&nbsp;5;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i--&nbsp;&gt;&nbsp;0)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;:&nbsp;Inner.m4t1()=&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(500);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;ie)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;m4t2()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i&nbsp;=&nbsp;5;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i--&nbsp;&gt;&nbsp;0)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;:&nbsp;Inner.m4t2()=&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(500);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;ie)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;m4t1(Inner&nbsp;inner)&nbsp;{&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronized(inner)&nbsp;{&nbsp;//使用对象锁&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inner.m4t1();&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;m4t2(Inner&nbsp;inner)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inner.m4t2();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;Foo&nbsp;myt3&nbsp;=&nbsp;new&nbsp;Foo();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;Inner&nbsp;inner&nbsp;=&nbsp;myt3.new&nbsp;Inner();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;t1&nbsp;=&nbsp;new&nbsp;Thread(new&nbsp;Runnable()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myt3.m4t1(inner);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&quot;t1&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;t2&nbsp;=&nbsp;new&nbsp;Thread(new&nbsp;Runnable()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;run()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myt3.m4t2(inner);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&quot;t2&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t1.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t2.start();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">结果：</span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">尽管线程t1获得了对Inner的对象锁，但由于线程t2访问的是同一个Inner中的非同步部分。所以两个线程互不干扰。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=0&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=0</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">现在在Inner.m4t2()前面加上synchronized：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">private&nbsp;synchronized&nbsp;void&nbsp;m4t2()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i&nbsp;=&nbsp;5;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i--&nbsp;&gt;&nbsp;0)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()&nbsp;+&nbsp;&quot;&nbsp;:&nbsp;Inner.m4t2()=&quot;&nbsp;+&nbsp;i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(500);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(InterruptedException&nbsp;ie)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">结果：</span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">尽管线程t1与t2访问了同一个Inner对象中两个毫不相关的部分,但因为t1先获得了对Inner的对象锁，所以t2对Inner.m4t2()的访问也被阻塞，因为m4t2()是Inner中的一个同步方法。</span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t1 : Inner.m4t1()=0&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=4&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=3&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=2&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=1&nbsp;&nbsp;</span><br style=\"margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: 微软雅黑, 微软雅黑, 微软雅黑; font-size: 14.44444465637207px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.77777862548828px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"/><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-size: 14.4444px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp; t2 : Inner.m4t2()=0</span></span></p><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\"><br/></span></p><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">java中synchronized用法：<br/><br/>&nbsp;&nbsp;&nbsp; 打个比方：一个object就像一个大房子，大门永远打开。房子里有 很多房间（也就是方法）。<br/><br/>&nbsp;&nbsp;&nbsp; 这些房间有上锁的（synchronized方法）， 和不上锁之分（普通方法）。房门口放着一把钥匙（key），这把钥匙可以打开所有上锁的房间。<br/><br/>另外我把所有想调用该对象方法的线程比喻成想进入这房子某个 房间的人。所有的东西就这么多了，下面我们看看这些东西之间如何作用的。<br/><br/>在此我们先来明确一下我们的前提条件。该对象至少有一个synchronized方法，否则这个key还有啥意义。当然也就不会有我们的这个主题了。<br/><br/>一个人想进入某间上了锁的房间，他来到房子门口，看见钥匙在那儿（说明暂时还没有其他人要使用上锁的 房间）。于是他走上去拿到了钥匙<br/><br/>，并且按照自己 的计划使用那些房间。注意一点，他每次使用完一次上锁的房间后会马上把钥匙还回去。即使他要连续使用两间上锁的房间，<br/><br/>中间他也要把钥匙还回去，再取回来。<br/><br/>&nbsp;&nbsp;&nbsp; 因此，普通情况下钥匙的使用原则是：“随用随借，用完即还。”<br/><br/>&nbsp;&nbsp;&nbsp; 这时其他人可以不受限制的使用那些不上锁的房间，一个人用一间可以，两个人用一间也可以，没限制。但是如果当某个人想要进入上锁的房<br/><br/>间，他就要跑到大门口去看看了。有钥匙当然拿了就走，没有的话，就只能等了。<br/><br/>&nbsp;&nbsp;&nbsp; 要是很多人在等这把钥匙，等钥匙还回来以后，谁会优先得到钥匙？Not guaranteed。象前面例子里那个想连续使用两个上锁房间的家伙，他<br/><br/>中间还钥匙的时候如果还有其他人在等钥匙，那么没有任何保证这家伙能再次拿到。 （JAVA规范在很多地方都明确说明不保证，象<br/><br/>Thread.sleep()休息后多久会返回运行，相同优先权的线程那个首先被执行，当要访问对象的锁被 释放后处于等待池的多个线程哪个会优先得<br/><br/>到，等等。我想最终的决定权是在JVM，之所以不保证，就是因为JVM在做出上述决定的时候，绝不是简简单单根据 一个条件来做出判断，而是<br/><br/>根据很多条。而由于判断条件太多，如果说出来可能会影响JAVA的推广，也可能是因为知识产权保护的原因吧。SUN给了个不保证 就混过去了<br/><br/>。无可厚非。但我相信这些不确定，并非完全不确定。因为计算机这东西本身就是按指令运行的。即使看起来很随机的现象，其实都是有规律<br/><br/>可寻。学过 计算机的都知道，计算机里随机数的学名是伪随机数，是人运用一定的方法写出来的，看上去随机罢了。另外，或许是因为要想弄<br/><br/>的确定太费事，也没多大意义，所 以不确定就不确定了吧。）<br/><br/>&nbsp;&nbsp;&nbsp; 再来看看同步代码块。和同步方法有小小的不同。<br/><br/>&nbsp;&nbsp;&nbsp; 1.从尺寸上讲，同步代码块比同步方法小。你可以把同步代码块看成是没上锁房间里的一块用带锁的屏风隔开的空间。<br/><br/>&nbsp;&nbsp;&nbsp; 2.同步代码块还可以人为的指定获得某个其它对象的key。就像是指定用哪一把钥匙才能开这个屏风的锁，你可以用本房的钥匙；你也可以指定<br/><br/>用另一个房子的钥匙才能开，这样的话，你要跑到另一栋房子那儿把那个钥匙拿来，并用那个房子的钥匙来打开这个房子的带锁的屏风。<br/><br/>记住你获得的那另一栋房子的钥匙，并不影响其他人进入那栋房子没有锁的房间。<br/><br/>&nbsp;&nbsp;&nbsp; 为什么要使用同步代码块呢？我想应该是这样的：首先对程序来讲同步的部分很影响运行效率，而一个方法通常是先创建一些局部变<br/><br/>量，再对这些变量做一些 操作，如运算，显示等等；而同步所覆盖的代码越多，对效率的影响就越严重。因此我们通常尽量缩小其影响范围。<br/><br/>如何做？同步代码块。我们只把一个方法中该同 步的地方同步，比如运算。<br/><br/>&nbsp;&nbsp;&nbsp; 另外，同步代码块可以指定钥匙这一特点有个额外的好处，是可以在一定时期内霸占某个对象的key。还记得前面说过普通情况下钥<br/><br/>匙的使用原则吗。现在不是普通情况了。你所取得的那把钥匙不是永远不还，而是在退出同步代码块时才还。<br/><br/>&nbsp;&nbsp;&nbsp; 还用前面那个想连续用两个上锁房间的家伙打比方。怎样才能在用完一间以后，继续使用另一间呢。用同步代码块吧。先创建另外<br/><br/>一个线程，做一个同步代码 块，把那个代码块的锁指向这个房子的钥匙。然后启动那个线程。只要你能在进入那个代码块时抓到这房子的钥匙<br/><br/>，你就可以一直保留到退出那个代码块。也就是说 你甚至可以对本房内所有上锁的房间遍历，甚至再sleep(10*60*1000)，而房门口却还有<br/><br/>1000个线程在等这把钥匙呢。很过瘾吧。<br/><br/>&nbsp;&nbsp;&nbsp; 在此对sleep()方法和钥匙的关联性讲一下。一个线程在拿到key后，且没有完成同步的内容时，如果被强制sleep()了，那key还一<br/><br/>直在 它那儿。直到它再次运行，做完所有同步内容，才会归还key。记住，那家伙只是干活干累了，去休息一下，他并没干完他要干的事。为<br/><br/>了避免别人进入那个房间 把里面搞的一团糟，即使在睡觉的时候他也要把那唯一的钥匙戴在身上。<br/><br/>&nbsp;&nbsp;&nbsp; 最后，也许有人会问，为什么要一把钥匙通开，而不是一个钥匙一个门呢？我想这纯粹是因为复杂性问题。一个钥匙一个门当然更<br/><br/>安全，但是会牵扯好多问题。钥匙 的产生，保管，获得，归还等等。其复杂性有可能随同步方法的增加呈几何级数增加，严重影响效率。这也<br/><br/>算是一个权衡的问题吧。为了增加一点点安全性，导致效 率大大降低，是多么不可取啊。<br/><br/>synchronized的一个简单例子：<br/></span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">package com.zb.notify;<br/><br/>public class TextThread {<br/><br/> &nbsp; &nbsp;public static void main(String[] args) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;TxtThread tt = new TxtThread();<br/> &nbsp; &nbsp; &nbsp; &nbsp;new Thread(tt).start();<br/> &nbsp; &nbsp; &nbsp; &nbsp;new Thread(tt).start();<br/> &nbsp; &nbsp; &nbsp; &nbsp;new Thread(tt).start();<br/> &nbsp; &nbsp; &nbsp; &nbsp;new Thread(tt).start();<br/> &nbsp; &nbsp;}<br/>}<br/><br/>class TxtThread implements Runnable {<br/> &nbsp; &nbsp;int num = 100;<br/> &nbsp; &nbsp;String str = new String();<br/><br/> &nbsp; &nbsp;public void run() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;synchronized (str) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (num &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread.sleep(1);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.getMessage();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(Thread.currentThread().getName() + &quot;this is &quot; + num--);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑,微软雅黑,微软雅黑; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 27.7778px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\"></span></p><p style=\"margin: 10px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana,Geneva,Arial,Helvetica,sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; background-color: rgb(255, 255, 255); line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp; 上面的例子中为了制造一个时间差,也就是出错的机会,使用了Thread.sleep(10)<br/><br/>&nbsp;&nbsp;&nbsp; Java对多线程的支持与同步机制深受大家的喜爱，似乎看起来使用了synchronized关键字就可以轻松地解决多线程共享数据同步问题。到底如<br/><br/>何？――还得对synchronized关键字的作用进行深入了解才可定论。<br/><br/>&nbsp;&nbsp;&nbsp; 总的说来，synchronized关键字可以作为函数的修饰符，也可作为函数内的语句，也就是平时说的同步方法和同步语句块。<br/><br/>&nbsp;&nbsp;&nbsp; 如果再细的分类，synchronized可作用于instance变量、object reference（对象引用）、static函数和class literals(类名称字面常量)身上。<br/><br/>&nbsp;&nbsp;&nbsp; 在进一步阐述之前，我们需要明确几点：<br/><br/>&nbsp;&nbsp;&nbsp; A．无论synchronized关键字加在方法上还是对象上，它取得的锁都是对象，而不是把一段代码或函数当作锁――而且同步方法很可能还会被其他线程的对象访问。<br/><br/>&nbsp;&nbsp;&nbsp; B．每个对象只有一个锁（lock）与之相关联。<br/><br/>&nbsp;&nbsp;&nbsp; C．实现同步是要很大的系统开销作为代价的，甚至可能造成死锁，所以尽量避免无谓的同步控制。<br/><br/>&nbsp;&nbsp;&nbsp; 接着来讨论synchronized用到不同地方对代码产生的影响：<br/><br/>&nbsp;&nbsp;&nbsp; 假设P1、P2是同一个类的不同对象，这个类中定义了以下几种情况的同步块或同步方法，P1、P2就都可以调用它们。<br/><br/>1． 把synchronized当作函数修饰符时，示例代码如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><span style=\"font-size: 14px;\"> &nbsp; &nbsp;</span><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">public synchronized void methodAAA()<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;//….<br/> &nbsp; &nbsp;}<br/></span></p></code></code></code></p></code></pre><p style=\"margin: 10px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana,Geneva,Arial,Helvetica,sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; background-color: rgb(255, 255, 255); line-height: 1.5em;\"><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp; 这也就是同步方法，那这时synchronized锁定的是哪个对象呢？它锁定的是调用这个同步方法对象。也就是说，当一个对象P1在不同的线程中<br/><br/>执行这个同步方法时，它们之间会形成互斥，达到同步的效果。但是这个对象所属的Class所产生的另一对象P2却可以任意调用这个被加了synchronized关键字的方法。<br/><br/>上边的示例代码等同于如下代码：</span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">public void methodAAA(){<br/> &nbsp; &nbsp;synchronized (this)// (1)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; //…<br/> &nbsp; &nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">(1)处的this指的是什么呢？它指的就是调用这个方法的对象，如P1。可见同步方法实质是将synchronized作用于object reference。那个<br/><br/>拿到了P1对象锁的线程，才可以调用P1的同步方法，而对P2而言，P1这个锁与它毫不相干，程序也可能在这种情形下摆脱同步机制的控制，造<br/><br/>成数据混乱。<br/><br/>2．同步块，示例代码如下：<br/></span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">public void method3(SomeObject so){<br/> &nbsp; &nbsp;synchronized(so){ <br/> &nbsp; &nbsp; &nbsp; //…<br/> &nbsp; &nbsp;}<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">这时，锁就是so这个对象，谁拿到这个锁谁就可以运行它所控制的那段代码。当有一个明确的对象作为锁时，就可以这样写程序，但当没有明<br/><br/>确的对象作为锁，只是想让一段代码同步时，可以创建一个特殊的instance变量（它得是一个对象）来充当锁：<br/></span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">class Foo implements Runnable{<br/> &nbsp; &nbsp;private byte[] lock = new byte[0]; // 特殊的instance变量<br/> &nbsp; &nbsp;Public void methodA() {<br/> &nbsp; &nbsp; &nbsp; synchronized(lock) { <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //… <br/> &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;//…<br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">注：零长度的byte数组对象创建起来将比任何对象都经济――查看编译后的字节码：生成零长度的byte[]对象只需3条操作码，而Object lock = new Object()则需要7行操作码。<br/><br/>3．将synchronized作用于static 函数，示例代码如下：<br/></span></p><pre class=\"brush:java;toolbar:false\"><code><p style=\"line-height: 1.5em;\"><code><code><code><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">class Foo{<br/> &nbsp; &nbsp;public synchronized static void methodAAA() // 同步的static 函数 <br/> &nbsp; &nbsp;{ <br/> &nbsp; &nbsp; &nbsp; &nbsp;//…<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;public void methodBBB() {<br/> &nbsp; &nbsp; &nbsp; synchronized(Foo.class);// class literal(类名称字面常量)<br/> &nbsp; &nbsp;} <br/>}<br/></span></p></code></code></code></p></code></pre><p style=\"line-height: 1.5em;\"><span style=\"font-size: 14px;\">代码中的methodBBB()方法是把class literal作为锁的情况，它和同步的static函数产生的效果是一样的，取得的锁很特别，是当前调用这<br/><br/>个方法的对象所属的类（Class，而不再是由这个Class产生的某个具体对象了）。<br/><br/>《Effective Java》一书中看到过将 Foo.class和 P1.getClass()用于作同步锁还不一样，不能用P1.getClass()来达到锁这个Class的<br/><br/>目的。P1指的是由Foo类产生的对象。<br/><br/>可以推断：如果一个类中定义了一个synchronized的static函数A，也定义了一个synchronized 的instance函数B，那么这个类的同一对象Obj<br/><br/>在多线程中分别访问A和B两个方法时，不会构成同步，因为它们的锁都不一样。B方法的锁是Obj这个对象，而A的锁是Obj所属的那个Class。<br/><br/><br/>小结如下：<br/><br/>搞清楚synchronized锁定的是哪个对象，就能帮助我们设计更安全的多线程程序。<br/><br/>还有一些技巧可以让我们对共享资源的同步访问更加安全：<br/><br/>1． 定义private 的instance变量+它的 get方法，而不要定义public/protected的instance变量。如果将变量定义为public，对象在外界可以<br/><br/>绕过同步方法的控制而直接取得它，并改动它。这也是JavaBean的标准实现方式之一。<br/><br/>2． 如果instance变量是一个对象，如数组或ArrayList什么的，那上述方法仍然不安全，因为当外界对象通过get方法拿到这个instance对象<br/><br/>的引用后，又将其指向另一个对象，那么这个private变量也就变了，岂不是很危险。 这个时候就需要将get方法也加上synchronized同步，并<br/><br/>且，只返回这个private对象的clone()――这样，调用端得到的就是对象副本的引用了<br/></span></p><p style=\"line-height: 19.5px; margin: 10px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><br/></p>','2015-06-02 11:42:23','2015-06-02 11:42:23','55631ee26ec09df591a730ed','1','synchronized：Java语言的关键字，当它用来修饰一个方法或者一个代码块的时候，能够保证在同一时刻最多只有一个线程执行该段代码。',1,NULL,1),('559b5fa393819df50d06f297','jQuery插件开发精品教程，让你的jQuery提升一个台阶','<p><span style=\"font-size: 20px;\"><strong>jQuery插件开发模式</strong></span></p><p><span style=\"font-size: 14px;\">根据《jQuery高级编程》的描述，jQuery插件开发方式主要有三种：</span></p><ol style=\"list-style-type: num;\" class=\"custom_num list-paddingleft-1\"><li class=\"list-num-1-1 list-num-paddingleft-1\"><p><span style=\"font-size: 14px;\">通过$.extend()来扩展jQuery</span></p></li><li class=\"list-num-1-2 list-num-paddingleft-1\"><p><span style=\"font-size: 14px;\">通过$.fn 向jQuery添加新的方法</span></p></li><li class=\"list-num-1-3 list-num-paddingleft-1\"><p><span style=\"font-size: 14px;\">通过$.widget()应用jQuery UI的部件工厂方式创建</span></p></li></ol><p><span style=\"font-size: 14px;\">通常我们使用第二种方法来进行简单插件开发，说简单是相对于第三种方式。第三种方式是用来开发更高级jQuery部件的，该模式开发出来的部件带有很多jQuery内建的特性，比如插件的状态信息自动保存，各种关于插件的常用方法等，非常贴心，这里不细说。</span></p><p><span style=\"font-size: 14px;\">而第一种方式又太简单，仅仅是在jQuery命名空间或者理解成jQuery身上添加了一个静态方法而以。所以我们调用通过$.extend()添加的函数时直接通过$符号调用（$.myfunction()）而不需要选中DOM元素($(&#39;#example&#39;).myfunction())。请看下面的例子。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.extend({<br/>&nbsp;&nbsp;&nbsp;&nbsp;sayHello:&nbsp;function(name)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(&#39;Hello,&#39;&nbsp;+&nbsp;(name&nbsp;?&nbsp;name&nbsp;:&nbsp;&#39;Dude&#39;)&nbsp;+&nbsp;&#39;!&#39;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>})<br/>$.sayHello();&nbsp;//调用<br/>$.sayHello(&#39;Wayou&#39;);&nbsp;//带参调用<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">运行结果：</span></p><p><img src=\"/resources/attached/image/201508251440469858257052707.png\" title=\"201508251440469858257052707.png\" alt=\"1.png\"/></p><p><span style=\"font-size: 14px;\">上面代码中，通过$.extend()向jQuery添加了一个sayHello函数，然后通过$直接调用。到此你可以认为我们已经完成了一个简单的jQuery插件了。<br/><br/>但如你所见，这种方式用来定义一些辅助方法是比较方便的。比如一个自定义的console，输出特定格式的信息，定义一次后可以通过jQuery在程序中任何需要的地方调用它。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.extend({<br/>&nbsp;&nbsp;&nbsp;&nbsp;log:&nbsp;function(message)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;now&nbsp;=&nbsp;new&nbsp;Date(),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y&nbsp;=&nbsp;now.getFullYear(),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m&nbsp;=&nbsp;now.getMonth()&nbsp;+&nbsp;1,&nbsp;//！JavaScript中月分是从0开始的<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;=&nbsp;now.getDate(),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h&nbsp;=&nbsp;now.getHours(),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min&nbsp;=&nbsp;now.getMinutes(),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;now.getSeconds(),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time&nbsp;=&nbsp;y&nbsp;+&nbsp;&#39;/&#39;&nbsp;+&nbsp;m&nbsp;+&nbsp;&#39;/&#39;&nbsp;+&nbsp;d&nbsp;+&nbsp;&#39;&nbsp;&#39;&nbsp;+&nbsp;h&nbsp;+&nbsp;&#39;:&#39;&nbsp;+&nbsp;min&nbsp;+&nbsp;&#39;:&#39;&nbsp;+&nbsp;s;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(time&nbsp;+&nbsp;&#39;&nbsp;My&nbsp;App:&nbsp;&#39;&nbsp;+&nbsp;message);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}})$.log(&#39;initializing...&#39;);&nbsp;//调用<br/></span></code></code></pre><p><img src=\"/resources/attached/image/201508251440469903201016244.png\" title=\"201508251440469903201016244.png\" alt=\"2.png\"/></p><p><span style=\"font-size: 14px;\">但这种方式无法利用jQuery强大的选择器带来的便利，要处理DOM元素以及将插件更好地运用于所选择的元素身上，还是需要使用第二种开发方式。你所见到或使用的插件也大多是通过此种方式开发。</span></p><p><br/></p><p><span style=\"color: rgb(0, 0, 0); font-size: 20px;\"><strong>插件开发</strong></span></p><p><span style=\"font-size: 14px;\">下面我们就来看第二种方式的jQuery插件开发。</span></p><p><span style=\"color: rgb(0, 0, 0); font-size: 14px;\"><strong>基本方法</strong></span></p><p><span style=\"font-size: 14px;\">先看一下它的基本格式：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.fn.pluginName&nbsp;=&nbsp;function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//your&nbsp;code&nbsp;goes&nbsp;here<br/>}<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">基本上就是往$.fn上面添加一个方法，名字是我们的插件名称。然后我们的插件代码在这个方法里面展开。<br/><br/>比如我们将页面上所有链接颜色转成红色，则可以这样写这个插件：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.fn.myPlugin&nbsp;=&nbsp;function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//在这里面,this指的是用jQuery选中的元素<br/>&nbsp;&nbsp;&nbsp;&nbsp;//example&nbsp;:$(&#39;a&#39;),则this=$(&#39;a&#39;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.css(&#39;color&#39;,&nbsp;&#39;red&#39;);<br/>}<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">在插件名字定义的这个函数内部，this指代的是我们在调用该插件时，用jQuery选择器选中的元素，一般是一个jQuery类型的集合。比如$(&#39;a&#39;)返回的是页面上所有a标签的集合，且这个集合已经是jQuery包装类型了，也就是说，在对其进行操作的时候可以直接调用jQuery的其他方法而不需要再用美元符号来包装一下。<br/><br/>所以在上面插件代码中，我们在this身上调用jQuery的css()方法，也就相当于在调用 $(&#39;a&#39;).css()。<br/><br/>理解this在这个地方的含义很重要。这样你才知道为什么可以直接商用jQuery方法同时在其他地方this指代不同时我们又需要用jQuery重新包装才能调用，下面会讲到。初学容易被this的值整晕，但理解了就不难。<br/><br/>现在就可以去页面试试我们的代码了，在页面上放几个链接，调用插件后链接字体变成红色。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">&lt;ul&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a&nbsp;href=&quot;http://www.webo.com/liuwayong&quot;&gt;我的微博&lt;/a&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a&nbsp;href=&quot;http://http://www.cnblogs.com/Wayou/&quot;&gt;我的博客&lt;/a&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a&nbsp;href=&quot;http://wayouliu.duapp.com/&quot;&gt;我的小站&lt;/a&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/li&gt;<br/>&lt;/ul&gt;<br/>&lt;p&gt;这是p标签不是a标签，我不会受影响&lt;/p&gt;<br/>&lt;script&nbsp;src=&quot;jquery-1.11.0.min.js&quot;&gt;&lt;/script&gt;<br/>&lt;script&nbsp;src=&quot;jquery.myplugin.js&quot;&gt;&lt;/script&gt;<br/>&lt;script&nbsp;type=&quot;text/javascript&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$(function(){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(&#39;a&#39;).myPlugin();<br/>&nbsp;&nbsp;&nbsp;&nbsp;})<br/>&lt;/script&gt;<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">运行结果：</span></p><p><img src=\"/resources/attached/image/201508251440469934660004166.png\" title=\"201508251440469934660004166.png\" alt=\"3.png\"/></p><p><span style=\"font-size: 14px;\">下面进一步，在插件代码里处理每个具体的元素，而不是对一个集合进行处理，这样我们就可以针对每个元素进行相应操作。<br/><br/>我们已经知道this指代jQuery选择器返回的集合，那么通过调用jQuery的.each()方法就可以处理合集中的每个元素了，但此刻要注意的是，在each方法内部，this指带的是普通的DOM元素了，如果需要调用jQuery的方法那就需要用$来重新包装一下。<br/><br/>比如现在我们要在每个链接显示链接的真实地址，首先通过each遍历所有a标签，然后获取href属性的值再加到链接文本后面。<br/><br/>更改后我们的插件代码为：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.fn.myPlugin&nbsp;=&nbsp;function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//在这里面,this指的是用jQuery选中的元素<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.css(&#39;color&#39;,&nbsp;&#39;red&#39;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.each(function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//对每个元素进行操作<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).append(&#39;&nbsp;&#39;&nbsp;+&nbsp;$(this).attr(&#39;href&#39;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;}))<br/>}<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">调用代码还是一样的，我们通过选中页面所有的a标签来调用这个插件<br/><br/>运行结果：</span></p><p><img src=\"/resources/attached/image/201508251440469963637095255.png\" title=\"201508251440469963637095255.png\" alt=\"4.png\"/></p><p><span style=\"font-size: 14px;\">到此，你已经可以编写功能简单的jQuery插件了。是不是也没那么难。<br/><br/>下面开始jQuery插件编写中一个重要的部分，参数的接收。</span></p><h2 style=\"margin: 20px 20px 20px 0px; padding: 0px; font-size: 21px; font-weight: bold; color: rgb(0, 0, 0); font-family: &#39;Microsoft YaHei&#39;, arial; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: 14px;\">支持链式调用</span></h2><p><span style=\"font-size: 14px;\">我们都知道jQuery一个时常优雅的特性是支持链式调用，选择好DOM元素后可以不断地调用其他方法。<br/><br/>要让插件不打破这种链式调用，只需return一下即可。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.fn.myPlugin&nbsp;=&nbsp;function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//在这里面,this指的是用jQuery选中的元素<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.css(&#39;color&#39;,&nbsp;&#39;red&#39;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.each(function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//对每个元素进行操作<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).append(&#39;&nbsp;&#39;&nbsp;+&nbsp;$(this).attr(&#39;href&#39;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;}))<br/>}<br/></span></code></code></pre><h2 style=\"margin: 20px 20px 20px 0px; padding: 0px; font-size: 21px; font-weight: bold; color: rgb(0, 0, 0); font-family: &#39;Microsoft YaHei&#39;, arial; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: 14px;\">让插件接收参数</span></h2><p><span style=\"font-size: 14px;\">一个强劲的插件是可以让使用者随意定制的，这要求我们提供在编写插件时就要考虑得全面些，尽量提供合适的参数。<br/><br/>比如现在我们不想让链接只变成红色，我们让插件的使用者自己定义显示什么颜色，要做到这一点很方便，只需要使用者在调用的时候传入一个参数即可。同时我们在插件的代码里面接收。另一方面，为了灵活，使用者可以不传递参数，插件里面会给出参数的默认值。<br/><br/>在处理插件参数的接收上，通常使用jQuery的extend方法，上面也提到过，但那是给extend方法传递单个对象的情况下，这个对象会合并到jQuery身上，所以我们就可以在jQuery身上调用新合并对象里包含的方法了，像上面的例子。当给extend方法传递一个以上的参数时，它会将所有参数对象合并到第一个里。同时，如果对象中有同名属性时，合并的时候后面的会覆盖前面的。<br/><br/>利用这一点，我们可以在插件里定义一个保存插件参数默认值的对象，同时将接收来的参数对象合并到默认对象上，最后就实现了用户指定了值的参数使用指定的值，未指定的参数使用插件默认值。<br/><br/>为了演示方便，再指定一个参数fontSize，允许调用插件的时候设置字体大小。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.fn.myPlugin&nbsp;=&nbsp;function(options)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;defaults&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;red&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;12px&#39;<br/>&nbsp;&nbsp;&nbsp;&nbsp;};<br/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;settings&nbsp;=&nbsp;$.extend(defaults,&nbsp;options);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.css({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;settings.color,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;settings.fontSize<br/>&nbsp;&nbsp;&nbsp;&nbsp;});<br/>}<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">现在，我们调用的时候指定颜色，字体大小未指定，会运用插件里的默认值12px。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$(&#39;a&#39;).myPlugin({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;#2C9929&#39;<br/>});<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">运行结果：</span></p><p><img src=\"/resources/attached/image/201508251440469988639007836.png\" title=\"201508251440469988639007836.png\" alt=\"5.png\"/></p><p><span style=\"font-size: 14px;\">同时指定颜色与字体大小：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$(&#39;a&#39;).myPlugin({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;#2C9929&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;20px&#39;<br/>});<br/></span></code></code></pre><p><img src=\"/resources/attached/image/201508251440470014007061573.png\" title=\"201508251440470014007061573.png\" alt=\"6.png\"/></p><h3 style=\"margin: 20px 20px 20px 0px; padding: 0px; font-size: 16px; font-weight: bold; color: rgb(0, 0, 0); font-family: &#39;Microsoft YaHei&#39;, arial; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: 14px;\">保护好默认参数</span></h3><p><span style=\"font-size: 14px;\">注意到上面代码调用extend时会将defaults的值改变，这样不好，因为它作为插件因有的一些东西应该维持原样，另外就是如果你在后续代码中还要使用这些默认值的话，当你再次访问它时它已经被用户传进来的参数更改了。</span></p><p><img src=\"/resources/attached/image/201508251440470036428079741.png\" title=\"201508251440470036428079741.png\" alt=\"7.png\"/></p><p><span style=\"font-size: 14px;\">一个好的做法是将一个新的空对象做为$.extend的第一个参数，defaults和用户传递的参数对象紧随其后，这样做的好处是所有值被合并到这个空对象上，保护了插件里面的默认值。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$.fn.myPlugin&nbsp;=&nbsp;function(options)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;defaults&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;red&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;12px&#39;<br/>&nbsp;&nbsp;&nbsp;&nbsp;};<br/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;settings&nbsp;=&nbsp;$.extend({},defaults,&nbsp;options);//将一个空对象做为第一个参数<br/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.css({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;settings.color,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;settings.fontSize<br/>&nbsp;&nbsp;&nbsp;&nbsp;});<br/>}<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">到此，插件可以接收和处理参数后，就可以编写出更健壮而灵活的插件了。若要编写一个复杂的插件，代码量会很大，如何组织代码就成了一个需要面临的问题，没有一个好的方式来组织这些代码，整体感觉会杂乱无章，同时也不好维护，所以将插件的所有方法属性包装到一个对象上，用面向对象的思维来进行开发，无疑会使工作轻松很多。</span></p><h2 style=\"margin: 20px 20px 20px 0px; padding: 0px; font-size: 21px; font-weight: bold; color: rgb(0, 0, 0); font-family: &#39;Microsoft YaHei&#39;, arial; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: 14px;\">面向对象的插件开发</span></h2><p><span style=\"font-size: 14px;\">为什么要有面向对象的思维，因为如果不这样，你可能需要一个方法的时候就去定义一个function，当需要另外一个方法的时候，再去随便定义一个function，同样，需要一个变量的时候，毫无规则地定义一些散落在代码各处的变量。<br/><br/>还是老问题，不方便维护，也不够清晰。当然，这些问题在代码规模较小时是体现不出来的。<br/><br/>如果将需要的重要变量定义到对象的属性上，函数变成对象的方法，当我们需要的时候通过对象来获取，一来方便管理，二来不会影响外部命名空间，因为所有这些变量名还有方法名都是在对象内部。<br/><br/>接着上面的例子，我们可以把这个插件抽象成一个美化页面的对象，因为他的功能是设置颜色啊字体啊什么的，当然我们还可以加入其他功能比如设置下划线啊什么的。当然对于这个例子抽象成对象有点小题大做，这里仅作演示用。以后我可能会介绍我编写的一个jQuery插件SlipHover,其中代码就比较多，这样的模式就用得上了。<br/><br/>所以我们新建一个对象命名为Beautifier，然后我们在插件里使用这个对象来编码。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">//定义Beautifier的构造函数<br/>var&nbsp;Beautifier&nbsp;=&nbsp;function(ele,&nbsp;opt)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.$element&nbsp;=&nbsp;ele,<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.defaults&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;red&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;12px&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;textDecoration&#39;:&#39;none&#39;<br/>&nbsp;&nbsp;&nbsp;&nbsp;},<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.options&nbsp;=&nbsp;$.extend({},&nbsp;this.defaults,&nbsp;opt)<br/>}<br/>//定义Beautifier的方法<br/>Beautifier.prototype&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;beautify:&nbsp;function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.$element.css({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;this.options.color,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;this.options.fontSize,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;textDecoration&#39;:&nbsp;this.options.textDecoration<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/>//在插件中使用Beautifier对象<br/>$.fn.myPlugin&nbsp;=&nbsp;function(options)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//创建Beautifier的实体<br/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;beautifier&nbsp;=&nbsp;new&nbsp;Beautifier(this,&nbsp;options);<br/>&nbsp;&nbsp;&nbsp;&nbsp;//调用其方法<br/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;beautifier.beautify();<br/>}<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">通过上面这样一改造，我们的代码变得更面向对象了，也更好维护和理解，以后要加新功能新方法，只需向对象添加新变量及方法即可，然后在插件里实例化后即可调用新添加的东西。<br/><br/>插件的调用还是一样的，我们对代码的改动并不影响插件其他地方，只是将代码的组织结构改动了而以。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$(function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;$(&#39;a&#39;).myPlugin({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;#2C9929&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;20px&#39;<br/>&nbsp;&nbsp;&nbsp;&nbsp;});<br/>})<br/></span></code></code></pre><p><img src=\"/resources/attached/image/201508251440470063850051171.png\" title=\"201508251440470063850051171.png\" alt=\"8.png\"/></p><p><span style=\"font-size: 14px;\">指定文字带下划线（我们在Beautifier对象中新加的功能，默认不带下划线，如上面的例子）的调用：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">$(function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;$(&#39;a&#39;).myPlugin({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;#2C9929&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;20px&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;textDecoration&#39;:&nbsp;&#39;underline&#39;<br/>&nbsp;&nbsp;&nbsp;&nbsp;});<br/>})<br/></span></code></code></pre><p><img src=\"/resources/attached/image/201508251440470086437012232.png\" title=\"201508251440470086437012232.png\" alt=\"9.png\"/></p><p><span style=\"font-size: 14px;\">到这里，你可以更好地编写复杂的插件同时很好地组织代码了。当我们回头去看上面的代码时，其实也还是有改进空间的。也就是下面介绍的关于命名空间及变量各什么的，一些杂项。</span></p><h2 style=\"margin: 20px 20px 20px 0px; padding: 0px; font-size: 21px; font-weight: bold; color: rgb(0, 0, 0); font-family: &#39;Microsoft YaHei&#39;, arial; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: 14px;\">关于命名空间</span></h2><p><span style=\"font-size: 14px;\">不仅仅是jQuery插件的开发，我们在写任何JS代码时都应该注意的一点是不要污染全局命名空间。因为随着你代码的增多，如果有意无意在全局范围内定义一些变量的话，最后很难维护，也容易跟别人写的代码有冲突。<br/><br/>比如你在代码中向全局window对象添加了一个变量status用于存放状态，同时页面中引用了另一个别人写的库，也向全局添加了这样一个同名变量，最后的结果肯定不是你想要的。所以不到万不得已，一般我们不会将变量定义成全局的。<br/><br/>一个好的做法是始终用自调用匿名函数包裹你的代码，这样就可以完全放心，安全地将它用于任何地方了，绝对没有冲突。</span></p><h3 style=\"margin: 20px 20px 20px 0px; padding: 0px; font-size: 16px; font-weight: bold; color: rgb(0, 0, 0); font-family: &#39;Microsoft YaHei&#39;, arial; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: 14px;\">用自调用匿名函数包裹你的代码</span></h3><p><span style=\"font-size: 14px;\">我们知道JavaScript中无法用花括号方便地创建作用域，但函数却可以形成一个作用域，域内的代码是无法被外界访问的。如果我们将自己的代码放入一个函数中，那么就不会污染全局命名空间，同时不会和别的代码冲突。<br/><br/>如上面我们定义了一个Beautifier全局变量，它会被附到全局的window对象上，为了防止这种事情发生，你或许会说，把所有代码放到jQuery的插件定义代码里面去啊，也就是放到$.fn.myPlugin里面。这样做倒也是种选择。但会让我们实际跟插件定义有关的代码变得臃肿，而在$.fn.myPlugin里面我们其实应该更专注于插件的调用，以及如何与jQuery互动。<br/><br/>所以保持原来的代码不变，我们将所有代码用自调用匿名函数包裹。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">(function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//定义Beautifier的构造函数<br/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;Beautifier&nbsp;=&nbsp;function(ele,&nbsp;opt)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.$element&nbsp;=&nbsp;ele,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.defaults&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;red&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;12px&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;textDecoration&#39;:&nbsp;&#39;none&#39;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.options&nbsp;=&nbsp;$.extend({},&nbsp;this.defaults,&nbsp;opt)<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;//定义Beautifier的方法<br/>&nbsp;&nbsp;&nbsp;&nbsp;Beautifier.prototype&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;beautify:&nbsp;function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.$element.css({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;this.options.color,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;this.options.fontSize,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;textDecoration&#39;:&nbsp;this.options.textDecoration<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;//在插件中使用Beautifier对象<br/>&nbsp;&nbsp;&nbsp;&nbsp;$.fn.myPlugin&nbsp;=&nbsp;function(options)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//创建Beautifier的实体<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;beautifier&nbsp;=&nbsp;new&nbsp;Beautifier(this,&nbsp;options);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//调用其方法<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;beautifier.beautify();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>})();<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">这样做的好处，也就是上面所阐述的那样。另外还有一个好处就是，自调用匿名函数里面的代码会在第一时间执行，页面准备好过后，上面的代码就将插件准备好了，以方便在后面的代码中使用插件。<br/><br/>目前为止似乎接近完美了。如果再考虑到其他一些因素，比如我们将这段代码放到页面后，前面别人写的代码没有用分号结尾，或者前面的代码将window, undefined等这些系统变量或者关键字修改掉了，正好我们又在自己的代码里面进行了使用，那结果也是不可预测的，这不是 我们想要的。我知道其实你还没太明白，下面详细介绍。</span></p><h3 style=\"margin: 20px 20px 20px 0px; padding: 0px; font-size: 16px; font-weight: bold; color: rgb(0, 0, 0); font-family: &#39;Microsoft YaHei&#39;, arial; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);\"><span style=\"font-size: 14px;\">将系统变量以变量形式传递到插件内部</span></h3><p><span style=\"font-size: 14px;\">来看下面的代码，你猜他会出现什么结果？</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">var&nbsp;foo=function(){<br/>&nbsp;&nbsp;&nbsp;&nbsp;//别人的代码<br/>}//注意这里没有用分号结尾//开始我们的代码。。。<br/><br/>(function(){<br/>&nbsp;&nbsp;&nbsp;&nbsp;//我们的代码。。<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(&#39;Hello!&#39;);<br/>})();<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">本来别人的代码也正常工作，只是最后定义的那个函数没有用分号结尾而以，然后当页面中引入我们的插件时，报错了，我们的代码无法正常执行。</span></p><p><img src=\"/resources/attached/image/201508251440470120239063518.png\" title=\"201508251440470120239063518.png\" alt=\"10.png\"/></p><p><span style=\"font-size: 14px;\">原因是我们用来充当自调用匿名函数的第一对括号与上面别人定义的函数相连，因为中间没有分号嘛，总之我们的代码无法正常解析了，所以报错。<br/><br/>所以好的做法是我们在代码开头加一个分号，这在任何时候都是一个好的习惯。</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">var&nbsp;foo=function(){<br/>&nbsp;&nbsp;&nbsp;&nbsp;//别人的代码<br/>}//注意这里没有用分号结尾<br/><br/>//开始我们的代码。。。<br/>;(function(){<br/>&nbsp;&nbsp;&nbsp;&nbsp;//我们的代码。。<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(&#39;Hello!&#39;);<br/>})();<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">同时，将系统变量以参数形式传递到插件内部也是个不错的实践。<br/><br/>当我们这样做之后，window等系统变量在插件内部就有了一个局部的引用，可以提高访问速度，会有些许性能的提升<br/><br/>最后我们得到一个非常安全结构良好的代码：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">;(function($,window,document,undefined){<br/>&nbsp;&nbsp;&nbsp;&nbsp;//我们的代码。。<br/>&nbsp;&nbsp;&nbsp;&nbsp;//blah&nbsp;blah&nbsp;blah...<br/>})(jQuery,window,document);<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">而至于这个undefined，稍微有意思一点，为了得到没有被修改的undefined，我们并没有传递这个参数，但却在接收时接收了它，因为实际并没有传，所以‘undefined’那个位置接收到的就是真实的&#39;undefined&#39;了。是不是有点hack的味道，值得细细体会的技术，当然不是我发明的，都是从前人的经验中学习。<br/><br/>所以最后我们的插件成了这样：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">;(function($,&nbsp;window,&nbsp;document,undefined)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//定义Beautifier的构造函数<br/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;Beautifier&nbsp;=&nbsp;function(ele,&nbsp;opt)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.$element&nbsp;=&nbsp;ele,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.defaults&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;&#39;red&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;&#39;12px&#39;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;textDecoration&#39;:&nbsp;&#39;none&#39;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.options&nbsp;=&nbsp;$.extend({},&nbsp;this.defaults,&nbsp;opt)<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;//定义Beautifier的方法<br/>&nbsp;&nbsp;&nbsp;&nbsp;Beautifier.prototype&nbsp;=&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;beautify:&nbsp;function()&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.$element.css({<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;color&#39;:&nbsp;this.options.color,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;fontSize&#39;:&nbsp;this.options.fontSize,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;textDecoration&#39;:&nbsp;this.options.textDecoration<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;//在插件中使用Beautifier对象<br/>&nbsp;&nbsp;&nbsp;&nbsp;$.fn.myPlugin&nbsp;=&nbsp;function(options)&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//创建Beautifier的实体<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;beautifier&nbsp;=&nbsp;new&nbsp;Beautifier(this,&nbsp;options);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//调用其方法<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;beautifier.beautify();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>})(jQuery,&nbsp;window,&nbsp;document);<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">一个安全，结构良好，组织有序的插件编写完成。</span></p><p><span style=\"font-size: 14px;\"><br/></span></p><p><span style=\"font-size: 14px;\"><span style=\"font-size: 16px; color: rgb(0, 0, 0);\"><strong>关于变量定义及命名</strong></span><br/><br/>现在谈谈关于变量及方法等的命名，没有硬性规定，但为了规范，遵循一些约定还是很有必要的。<br/><br/><strong>变量定义</strong>：好的做法是把将要使用的变量名用一个var关键字一并定义在代码开头，变量名间用逗号隔开。原因有二：<br/><br/>一是便于理解，知道下面的代码会用到哪些变量，同时代码显得整洁且有规律，也方便管理，变量定义与逻辑代码分开；<br/>二是因为JavaScript中所有变量及函数名会自动提升，也称之为JavaScript的Hoist特性，即使你将变量的定义穿插在逻辑代码中，在代码解析运行期间，这些变量的声明还是被提升到了当前作用域最顶端的，所以我们将变量定义在一个作用域的开头是更符合逻辑的一种做法。当然，再次说明这只是一种约定，不是必需的。<br/><strong>变量及函数命名</strong> 一般使用驼峰命名法（CamelCase），即首个单词的首字母小写，后面单词首字母大写，比如resultArray，requestAnimationFrame。对于常量，所有字母采用大写，多个单词用下划线隔开，比如WIDTH=100，BRUSH_COLOR=&#39;#00ff00&#39;。当变量是jQuery类型时，建议以$开头，开始会不习惯，但经常用了之后会感觉很方便，因为可以很方便地将它与普通变量区别开来，一看到以$开头我们就知道它是jQuery类型可以直接在其身上调用jQuery相关的方法，比如var $element=$(&#39;a&#39;); 之后就可以在后面的代码中很方便地使用它，并且与其他变量容易区分开来。<br/><br/><strong>引号的使用</strong>：既然都扯了这些与插件主题无关的了，这里再多说一句，一般HTML代码里面使用双引号，而在JavaScript中多用单引号，比如下面代码所示：</span></p><pre class=\"brush:java;toolbar:false\"><code><code><span style=\"font-size: 14px;\">var&nbsp;name&nbsp;=&nbsp;&#39;Wayou&#39;;<br/>document.getElementById(‘example’).innerHTML&nbsp;=&nbsp;&#39;&lt;&nbsp;a&nbsp;href=&quot;http:&nbsp;//wayouliu.duapp.com/&quot;&gt;&#39;+name+&#39;&lt;/a&gt;&#39;;&nbsp;<br/>//href=&quot;..&quot;&nbsp;HTML中保持双引号，JavaScript中保持单引号<br/></span></code></code></pre><p><span style=\"font-size: 14px;\">一方面，HTML代码中本来就使用的是双引号，另一方面，在JavaScript中引号中还需要引号的时候，要求我们单双引号间隔着写才是合法的语句，除非你使用转意符那也是可以的。再者，坚持这样的统一可以保持代码风格的一致，不会出现这里字符串用双引号包着，另外的地方就在用单引号。</span></p><p><br/></p><p><span style=\"font-size: 14px;\"><span style=\"font-size: 20px;\"><strong>代码混淆与压缩</strong></span><br/><br/>进行完上面的步骤，已经小有所成了。或许你很早就注意到了，你下载的插件里面，一般都会提供一个压缩的版本一般在文件名里带个&#39;min&#39;字样。也就是minified的意思，压缩浓缩后的版本。并且平时我们使用的jQuery也是官网提供的压缩版本，jquery.min.js。</span></p><p><br/><span style=\"font-size: 14px;\">这里的压缩不是指代码进行功能上的压缩，而是通过将代码里面的变量名，方法函数名等等用更短的名称来替换，并且删除注释（如果有的话）删除代码间的空白及换行所得到的浓缩版本。同时由于代码里面的各种名称都已经被替代，别人无法阅读和分清其逻辑，也起到了混淆代码的作用。<br/><br/><strong>压缩的好处</strong><br/></span></p><ul class=\" list-paddingleft-2\" style=\"list-style-type: disc;\"><li><p><span style=\"font-size: 14px;\">源码经过混淆压缩后，体积大大减小，使代码变得轻量级，同时加快了下载速度，两面加载变快。比如正常jQuery v1.11.0的源码是276kb，而压缩后的版本仅94.1kb！体积减小一半还多。这个体积的减小对于文件下载速度的提升不可小觑。</span></p></li><li><p><span style=\"font-size: 14px;\">经过压缩混淆后，代码还能阅读嘛？当然不能，所以顺带还起到了代码保护的作用。当然只是针对你编写了一些比较酷的代码又不想别人抄袭的情况。对于jQuery社区，这里本身就是开源的世界，同时JavaScript这东西其实也没什么实质性方法可以防止别人查看阅读你的代码，毕竟有混淆就有反混淆工具，这里代码压缩更多的还是上面提到的压缩文件的作用，同时一定程度上防止别人抄袭。<br/></span></p></li></ul><p><br/><span style=\"font-size: 14px;\"><strong>工具</strong><br/><br/>所使用的工具推崇的是Google开发的Closure Compiler。该工具需要Java环境的支持，所以使用前你可能需要先在机子上装JRE, 然后再获取Closure进行使用。<br/>同时也有很朋在线的代码混淆压缩工具，用起来也很方便。这些工具都是一搜一大把的。<br/></span></p>','2015-07-07 13:12:03','2015-07-07 13:12:03','5','1','介绍使用Jquery开发插件的步骤方法，对于项目中的前端编码提供更好的优化途径，提升代码的质量。',1,NULL,1),('55c1d5b49780aee41cda2125','GodSon Easyui 结合Pluplaod插件的文件分割上传','<p><span style=\"font-size: 14px;\">自己整理了一个文件分割上传的实例，提供研究学习使用。</span></p><p><span style=\"font-family: 宋体; font-size: 14px;\"><br/></span></p><p><a textvalue=\"在线查看效果\" target=\"_blank\" href=\"/resources/demoSources/plupload/index.jsp\"><span style=\"font-size: 18px;\">在线查看效果</span></a><br/></p><p><br/></p><p><span style=\"font-size: 18px;\">下载该资源</span></p><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a textvalue=\"pluplaod文件分割上传Demo.zip\" title=\"pluplaod文件分割上传Demo.zip\" target=\"_self\" href=\"/resources/attached/file/pluplaod文件分割上传Demo.zip\"><span style=\"font-size: 14px;\">pluplaod文件分割上传Demo.zip</span></a></p><p><br/></p><p><span style=\"font-size: 20px; color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 20px; font-family: 宋体;\">简介：</span></strong></span></p><p><span style=\"font-family: 宋体; font-size: 14px;\">首先，进入页面会看到下面的效果：</span></p><p><img alt=\"11.jpg\" src=\"/resources/attached/image/201508051438766126762091845.jpg\" title=\"201508051438766126762091845.jpg\"/></p><p><br/></p><p><span style=\"font-family: 宋体; font-size: 14px;\">点击一个按钮，出现如图上传界面：</span></p><p><img alt=\"2.jpg\" src=\"/resources/attached/image/201508051438766171449088406.jpg\" title=\"201508051438766171449088406.jpg\"/></p><p><br/></p><p><span style=\"font-family: 宋体; font-size: 14px;\">选择一个文件后，会有大小、上传进度的提示：</span></p><p><img alt=\"3.jpg\" src=\"/resources/attached/image/201508051438766199652052357.jpg\" title=\"201508051438766199652052357.jpg\"/></p><p><br/></p><p><span style=\"font-family: 宋体; font-size: 14px;\">上传成功后，还会有回调提示：</span></p><p><img alt=\"4.jpg\" src=\"/resources/attached/image/201508051438766226090083931.jpg\" title=\"201508051438766226090083931.jpg\"/></p><p><br/></p><p><br/></p><p><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-family: 宋体; font-size: 20px;\">功能详解：</span></strong></span></p><p><span style=\"font-size: 14px;\"><span style=\"font-size: 14px; font-family: 宋体;\">从页面可以看出上传分为</span> <span style=\"font-size: 14px; font-family: 宋体;\">“不分割文件上传”</span> <span style=\"font-size: 14px; font-family: 宋体;\">、“分割文件上传”这</span>2<span style=\"font-size: 14px; font-family: 宋体;\">种上传方式，它们有什么区别呢？</span></span></p><p><span style=\"font-size: 14px;\">&nbsp;</span></p><p><span style=\"font-size: 14px;\"><span style=\"font-size: 14px; font-family: 宋体;\">我现在使用这</span>2<span style=\"font-size: 14px; font-family: 宋体;\">种方式上传同一个文件，在上传到</span>tomcat<span style=\"font-size: 14px; font-family: 宋体;\">服务器的过程中，效果如下：</span></span></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">1<span style=\"font-size: 14px; font-family: 宋体;\">、不分割文件上传</span></span></p><p><img alt=\"5.jpg\" src=\"/resources/attached/image/201508051438766265933012686.jpg\" title=\"201508051438766265933012686.jpg\"/></p><p><span style=\"font-size: 14px;\"><span style=\"font-size: 14px; font-family: 宋体;\">结果：目录下始终只有</span>1<span style=\"font-size: 14px; font-family: 宋体;\">个文件（后台自动编码中文名称的文件名）</span></span></p><p><span style=\"font-family: 宋体; font-size: 14px;\"><br/></span></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">2<span style=\"font-size: 14px; font-family: 宋体;\">、分割文件上传</span></span></p><p><span style=\"font-family: 宋体; font-size: 14px;\">上传过程中：</span></p><p><img alt=\"6.jpg\" src=\"/resources/attached/image/201508051438766299465003541.jpg\" title=\"201508051438766299465003541.jpg\"/></p><p><span style=\"font-family: 宋体; font-size: 14px;\">上传成功后：</span></p><p><img alt=\"7.jpg\" src=\"/resources/attached/image/201508051438766327840040228.jpg\" title=\"201508051438766327840040228.jpg\"/></p><p><span style=\"font-family: 宋体; font-size: 14px;\">结果：</span></p><p><span style=\"font-family: 宋体; font-size: 14px;\">文件被分割成好多个文件，依次上传，最终将这些小文件合并成原来的文件。好处是，不会造成网络拥堵，进一步提高上传的速度和效率。</span></p><p><br/></p><p><br/></p>','2015-08-05 09:21:56','2015-08-05 09:21:56','5','1','上传分为 “不分割文件上传” 、“分割文件上传”这2种上传方式，“分割文件上传”将文件分割成好多个小文件，依次上传，最终将这些小文件合并成原来的文件，进一步提供上传的速度和效率。',1,NULL,1),('55c40bfea643aee46bc477fc','JS实现精确加减乘除','<p><span style=\"font-size: 14px;\">说明：项目中要使用 JS 实现自动计算的功能，进行一些浮点数运算时，计算结果却是一长串的值，这里提供一个解决方法，问题基本上可以解决。</span></p><p><br/></p><p><span style=\"font-size: 14px;\">具体代码如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">//加法函数<br/>function accAdd(arg1, arg2) {<br/> &nbsp; &nbsp;var r1, r2, m;<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r1 = arg1.toString().split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r1 = 0;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r2 = arg2.toString().split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r2 = 0;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;m = Math.pow(10, Math.max(r1, r2));<br/> &nbsp; &nbsp;return (arg1 * m + arg2 * m) / m;<br/>} <br/>//给Number类型增加一个add方法，，使用时直接用 .add 即可完成计算。 <br/>Number.prototype.add = function (arg) {<br/> &nbsp; &nbsp;return accAdd(arg, this);<br/>};<br/><br/><br/>//减法函数<br/>function Subtr(arg1, arg2) {<br/> &nbsp; &nbsp;var r1, r2, m, n;<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r1 = arg1.toString().split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r1 = 0;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r2 = arg2.toString().split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r2 = 0;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;m = Math.pow(10, Math.max(r1, r2));<br/> &nbsp; &nbsp; //last modify by deeka<br/> &nbsp; &nbsp; //动态控制精度长度<br/> &nbsp; &nbsp;n = (r1 &gt;= r2) ? r1 : r2;<br/> &nbsp; &nbsp;return ((arg1 * m - arg2 * m) / m).toFixed(n);<br/>}<br/><br/>//给Number类型增加一个add方法，，使用时直接用 .sub 即可完成计算。 <br/>Number.prototype.sub = function (arg) {<br/> &nbsp; &nbsp;return Subtr(this, arg);<br/>};<br/><br/><br/>//乘法函数<br/>function accMul(arg1, arg2) {<br/> &nbsp; &nbsp;var m = 0, s1 = arg1.toString(), s2 = arg2.toString();<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;m += s1.split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;m += s2.split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;return Number(s1.replace(&quot;.&quot;, &quot;&quot;)) * Number(s2.replace(&quot;.&quot;, &quot;&quot;)) / Math.pow(10, m);<br/>} <br/>//给Number类型增加一个mul方法，使用时直接用 .mul 即可完成计算。 <br/>Number.prototype.mul = function (arg) {<br/> &nbsp; &nbsp;return accMul(arg, this);<br/>}; <br/><br/><br/>//除法函数<br/>function accDiv(arg1, arg2) {<br/> &nbsp; &nbsp;var t1 = 0, t2 = 0, r1, r2;<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;t1 = arg1.toString().split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp;t2 = arg2.toString().split(&quot;.&quot;)[1].length;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;catch (e) {<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;with (Math) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;r1 = Number(arg1.toString().replace(&quot;.&quot;, &quot;&quot;));<br/> &nbsp; &nbsp; &nbsp; &nbsp;r2 = Number(arg2.toString().replace(&quot;.&quot;, &quot;&quot;));<br/> &nbsp; &nbsp; &nbsp; &nbsp;return (r1 / r2) * pow(10, t2 - t1);<br/> &nbsp; &nbsp;}<br/>} <br/>//给Number类型增加一个div方法，，使用时直接用 .div 即可完成计算。 <br/>Number.prototype.div = function (arg) {<br/> &nbsp; &nbsp;return accDiv(this, arg);<br/>}; <br/></span></code></pre><p><br/></p><p><br/></p><p><span style=\"font-size: 14px;\">使用方法如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">//加法示例（其它的都类似）<br/>function calculate() {<br/> &nbsp; &nbsp;//数字1<br/> &nbsp; &nbsp;var num1 = 10;<br/> &nbsp; &nbsp;//数字2<br/> &nbsp; &nbsp;var num2 = 5;<br/> &nbsp; &nbsp;//计算 num1 + num2<br/> &nbsp; &nbsp;alert(num1.add(num2));<br/>}<br/></span></code></pre><p><br/></p>','2015-08-07 01:38:06','2015-08-07 01:38:06','5','1','项目中要使用 JS 实现自动计算的功能，进行一些浮点数运算时，计算结果却是一长串的值，这里提供一个解决方法，问题基本上可以解决。',1,NULL,1),('55c4124ca643aee46cc477fc','JavaScript 排序算法——快速排序','<p><span style=\"font-size: 20px;\"><strong>常见排序</strong></span></p><hr/><p><span style=\"font-size: 14px;\">javaScript 实现的常见排序算法有：冒泡排序、选择排序、插入排序、谢尔排序、快速排序(递归)、快速排序(堆栈)、归并排序、堆排序。</span></p><p><br/></p><p><span style=\"font-size: 20px;\"><strong>过程</strong></span></p><hr/><p><span style=\"font-size: 14px;\">&quot;快速排序&quot;的思想很简单，整个排序过程只需要三步：</span></p><p><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;1、在数据集之中，找一个基准点</span></p><p><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;2、建立两个数组，分别存储左边和右边的数组</span></p><p><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;3、利用递归进行下次比较</span></p><p><br/></p><p><span style=\"font-size: 20px;\"><strong>代码例子</strong></span></p><pre class=\"brush:java;toolbar:false\"><code><code><code><span style=\"font-size: 14px;\">&lt;script&nbsp;type=&quot;text/javascript&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;quickSort(arr){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(arr.length&lt;=1){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;arr;//如果数组只有一个数，就直接返回；<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;num&nbsp;=&nbsp;Math.floor(arr.length/2);//找到中间数的索引值，如果是浮点数，则向下取整<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;numValue&nbsp;=&nbsp;arr.splice(num,1);//找到中间数的值<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;left&nbsp;=&nbsp;[];<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;right&nbsp;=&nbsp;[];<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(var&nbsp;i=0;i&lt;arr.length;i++){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(arr[i]&lt;numValue){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;left.push(arr[i]);//基准点的左边的数传到左边数组<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;right.push(arr[i]);//基准点的右边的数传到右边数组<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;quickSort(left).concat([numValue],quickSort(right));//递归不断重复比较<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;alert(quickSort([32,45,37,16,2,87]));//弹出“2,16,32,37,45,87”<br/>&lt;/script&gt;<br/></span></code></code></code></pre><p><br/></p>','2015-08-07 02:05:00','2015-08-07 02:05:00','5','1','javaScript 实现的常见排序算法有：冒泡排序、选择排序、插入排序、谢尔排序、快速排序(递归)、快速排序(堆栈)、归并排序、堆排序。',1,NULL,1),('55c41a1fa643aee46dc477fc','IP工具类——IpAddress.java','<p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">根据IP地址获取详细的地域信息，也可通过 http://whois.pconline.com.cn/ 获取地址信息。</span></p><p><br/></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">源码如下：(点击下载&nbsp;</span><span style=\"font-size: 14px;\"> </span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"text-decoration: underline; font-size: 14px; color: rgb(247, 150, 70);\" href=\"/resources/attached/file/IpAddress.java\" title=\"IpAddress.java\"><span style=\"font-size: 14px; color: rgb(247, 150, 70);\">IpAddress.java</span></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">)</span><span style=\"font-size: 14px;\"><br/></span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">import java.io.BufferedReader;<br/>import java.io.DataOutputStream;<br/>import java.io.IOException;<br/>import java.io.InputStreamReader;<br/>import java.io.UnsupportedEncodingException;<br/>import java.net.HttpURLConnection;<br/>import java.net.URL;<br/><br/>/**<br/> * 根据IP地址获取详细的地域信息 <br/> * &nbsp; &nbsp; &nbsp;也可通过 http://whois.pconline.com.cn/ 获取地址信息<br/> * <br/> * 作者: zhoubang <br/> * 日期：2015年8月7日 上午10:25:00<br/> */<br/>public class IpAddress {<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获取IP所在地址<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * 作者: zhoubang <br/> &nbsp; &nbsp; * 日期：2015年8月7日 上午10:26:57<br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * @param encodingString<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; * @throws UnsupportedEncodingException<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public String getAddresses(String content, String encodingString)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throws UnsupportedEncodingException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 淘宝的接口<br/> &nbsp; &nbsp; &nbsp; &nbsp;String urlStr = &quot;http://ip.taobao.com/service/getIpInfo.php&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;String returnStr = this.getResult(urlStr, content, encodingString);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (returnStr != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 处理返回的省市区信息<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(returnStr);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String[] temp = returnStr.split(&quot;,&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (temp.length &lt; 3) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return &quot;0&quot;;// 无效IP，局域网测试<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String region = (temp[5].split(&quot;:&quot;))[1].replaceAll(&quot;\\&quot;&quot;, &quot;&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;region = decodeUnicode(region);// 省份<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String country = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String area = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// String region = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String city = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String county = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String isp = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; temp.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;switch (i) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 1:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;country = (temp[i].split(&quot;:&quot;))[2].replaceAll(&quot;\\&quot;&quot;, &quot;&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;country = decodeUnicode(country);// 国家<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 3:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;area = (temp[i].split(&quot;:&quot;))[1].replaceAll(&quot;\\&quot;&quot;, &quot;&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;area = decodeUnicode(area);// 地区<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 5:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;region = (temp[i].split(&quot;:&quot;))[1].replaceAll(&quot;\\&quot;&quot;, &quot;&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;region = decodeUnicode(region);// 省份<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 7:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;city = (temp[i].split(&quot;:&quot;))[1].replaceAll(&quot;\\&quot;&quot;, &quot;&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;city = decodeUnicode(city);// 市区<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 9:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;county = (temp[i].split(&quot;:&quot;))[1].replaceAll(&quot;\\&quot;&quot;, &quot;&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;county = decodeUnicode(county);// 地区<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 11:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;isp = (temp[i].split(&quot;:&quot;))[1].replaceAll(&quot;\\&quot;&quot;, &quot;&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;isp = decodeUnicode(isp); // ISP公司<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(country + &quot;=&quot; + area + &quot;=&quot; + region + &quot;=&quot; + city + &quot;=&quot; + county + &quot;=&quot; + isp);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return region;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 请求接口<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * 作者: zhoubang <br/> &nbsp; &nbsp; * 日期：2015年8月7日 上午10:27:45<br/> &nbsp; &nbsp; * @param urlStr<br/> &nbsp; &nbsp; * @param content<br/> &nbsp; &nbsp; * @param encoding<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;private String getResult(String urlStr, String content, String encoding) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;URL url = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;HttpURLConnection connection = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url = new URL(urlStr);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection = (HttpURLConnection) url.openConnection();// 新建连接实例<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.setConnectTimeout(10000);// 设置连接超时时间，单位毫秒<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.setReadTimeout(10000);// 设置读取数据超时时间，单位毫秒<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.setDoOutput(true);// 是否打开输出流 true|false<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.setDoInput(true);// 是否打开输入流true|false<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.setRequestMethod(&quot;POST&quot;);// 提交方法POST|GET<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.setUseCaches(false);// 是否缓存true|false<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.connect();// 打开连接端口<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DataOutputStream out = new DataOutputStream(connection.getOutputStream());// 打开输出流往对端服务器写数据<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out.writeBytes(content);// 写数据,也就是提交你的表单 name=xxx&amp;pwd=xxx<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out.flush();// 刷新<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out.close();// 关闭输出流<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StringBuffer buffer = new StringBuffer();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String line = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ((line = reader.readLine()) != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buffer.append(line);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reader.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return buffer.toString();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (connection != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connection.disconnect();// 关闭连接<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * unicode 转换成 中文<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @author fanhui 2007-3-15<br/> &nbsp; &nbsp; * @param theString<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String decodeUnicode(String theString) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;char aChar;<br/> &nbsp; &nbsp; &nbsp; &nbsp;int len = theString.length();<br/> &nbsp; &nbsp; &nbsp; &nbsp;StringBuffer outBuffer = new StringBuffer(len);<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int x = 0; x &lt; len;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aChar = theString.charAt(x++);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (aChar == &#39;\\\\&#39;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aChar = theString.charAt(x++);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (aChar == &#39;u&#39;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int value = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; 4; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aChar = theString.charAt(x++);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;switch (aChar) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;0&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;1&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;2&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;3&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;4&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;5&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;6&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;7&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;8&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;9&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value = (value &lt;&lt; 4) + aChar - &#39;0&#39;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;a&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;b&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;c&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;d&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;e&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;f&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value = (value &lt;&lt; 4) + 10 + aChar - &#39;a&#39;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;A&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;B&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;C&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;D&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;E&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &#39;F&#39;:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value = (value &lt;&lt; 4) + 10 + aChar - &#39;A&#39;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new IllegalArgumentException(&quot;Malformed &nbsp; &nbsp; &nbsp;encoding.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outBuffer.append((char) value);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (aChar == &#39;t&#39;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aChar = &#39;\\t&#39;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (aChar == &#39;r&#39;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aChar = &#39;\\r&#39;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (aChar == &#39;n&#39;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aChar = &#39;\\n&#39;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (aChar == &#39;f&#39;) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aChar = &#39;\\f&#39;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outBuffer.append(aChar);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outBuffer.append(aChar);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return outBuffer.toString();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;// 测试<br/> &nbsp; &nbsp;public static void main(String[] args) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;IpAddress addressUtils = new IpAddress();<br/> &nbsp; &nbsp; &nbsp; &nbsp;String ip = &quot;27.54.227.84&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;String address = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;address = addressUtils.getAddresses(&quot;ip=&quot; + ip, &quot;utf-8&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (UnsupportedEncodingException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(address);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 输出结果为：中国=华东=安徽省=滁州市==<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 安徽省<br/> &nbsp; &nbsp;}<br/>}<br/><br/></span></code></pre><p><br/></p>','2015-08-07 02:38:23','2015-08-07 02:38:23','5568000980689df542ea01f6','1','根据IP地址获取详细的地域信息，也可通过 http://whois.pconline.com.cn/ 获取地址信息。',1,NULL,1),('55c41d44a643aee46ec477fc','验证码图片生成工具类——Captcha.java','<p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">验证码图片生成工具，使用JAVA生成的图片验证码，调用getRandcode方法获取图片验证码，以流的方式传输到前端页面。</span></p><p><br/></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">源码如下：(点击下载&nbsp; </span><img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(247, 150, 70); text-decoration: underline;\" href=\"/resources/attached/file/Captcha.java\" title=\"Captcha.java\"><span style=\"color: rgb(247, 150, 70);\">Captcha.java</span></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">)</span><br/></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">import java.awt.Color;<br/>import java.awt.Font;<br/>import java.awt.Graphics;<br/>import java.awt.image.BufferedImage;<br/>import java.util.Random;<br/>import javax.imageio.ImageIO;<br/>import javax.servlet.http.HttpServletRequest;<br/>import javax.servlet.http.HttpServletResponse;<br/>import javax.servlet.http.HttpSession;<br/><br/>/**<br/> * 验证码图片生成工具<br/> * &nbsp;使用JAVA生成的图片验证码，调用getRandcode方法获取图片验证码，以流的方式传输到前端页面。<br/> * &nbsp;<br/> * <br/> * 作者: zhoubang <br/> * 日期：2015年8月7日 上午10:41:05<br/> */<br/>public class Captcha {<br/><br/> &nbsp; &nbsp;public static final String RANDOMCODEKEY = &quot;sess_captcha&quot;;// 放到session中的key<br/> &nbsp; &nbsp;private Random random = new Random();<br/> &nbsp; &nbsp;private String randString = &quot;0123456789&quot;;// 随机产生的字符串<br/><br/> &nbsp; &nbsp;private int width = 80;// 图片宽<br/> &nbsp; &nbsp;private int height = 26;// 图片高<br/> &nbsp; &nbsp;private int lineSize = 40;// 干扰线数量<br/> &nbsp; &nbsp;private int stringNum = 4;// 随机产生字符数量<br/><br/> &nbsp; &nbsp;/*<br/> &nbsp; &nbsp; * 获得字体<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;private Font getFont() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return new Font(&quot;Fixedsys&quot;, Font.CENTER_BASELINE, 18);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/*<br/> &nbsp; &nbsp; * 获得颜色<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;private Color getRandColor(int fc, int bc) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fc &gt; 255)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fc = 255;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (bc &gt; 255)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bc = 255;<br/> &nbsp; &nbsp; &nbsp; &nbsp;int r = fc + random.nextInt(bc - fc - 16);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int g = fc + random.nextInt(bc - fc - 14);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int b = fc + random.nextInt(bc - fc - 18);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return new Color(r, g, b);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/*<br/> &nbsp; &nbsp; * 绘制字符串<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;private String drowString(Graphics g, String randomString, int i) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.setFont(getFont());<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.setColor(new Color(random.nextInt(101), random.nextInt(111), random.nextInt(121)));<br/> &nbsp; &nbsp; &nbsp; &nbsp;String rand = String.valueOf(getRandomString(random.nextInt(randString.length())));<br/> &nbsp; &nbsp; &nbsp; &nbsp;randomString += rand;<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.translate(random.nextInt(3), random.nextInt(3));<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.drawString(rand, 13 * i, 16);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return randomString;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/*<br/> &nbsp; &nbsp; * 绘制干扰线<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;private void drowLine(Graphics g) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;int x = random.nextInt(width);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int y = random.nextInt(height);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int xl = random.nextInt(13);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int yl = random.nextInt(15);<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.drawLine(x, y, x + xl, y + yl);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/*<br/> &nbsp; &nbsp; * 获取随机的字符<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public String getRandomString(int num) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return String.valueOf(randString.charAt(num));<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 生成随机图片<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public void getRandcode(HttpServletRequest request, HttpServletResponse response) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;HttpSession session = request.getSession();<br/> &nbsp; &nbsp; &nbsp; &nbsp;// BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);<br/> &nbsp; &nbsp; &nbsp; &nbsp;Graphics g = image.getGraphics();// 产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.fillRect(0, 0, width, height);<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.setFont(new Font(&quot;Times New Roman&quot;, Font.ROMAN_BASELINE, 18));<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.setColor(getRandColor(110, 133));<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 绘制干扰线<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt;= lineSize; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;drowLine(g);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 绘制随机字符<br/> &nbsp; &nbsp; &nbsp; &nbsp;String randomString = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 1; i &lt;= stringNum; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;randomString = drowString(g, randomString, i);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;session.removeAttribute(RANDOMCODEKEY);<br/> &nbsp; &nbsp; &nbsp; &nbsp;session.setAttribute(RANDOMCODEKEY, randomString);<br/> &nbsp; &nbsp; &nbsp; &nbsp;g.dispose();<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageIO.write(image, &quot;JPEG&quot;, response.getOutputStream());// 将内存中的图片通过流动形式输出到客户端<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/>}<br/></span></code></pre><p><br/></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">简单使用方法（可自行设计，此方法为servlet调用）：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">import java.io.IOException;<br/>import javax.servlet.ServletException;<br/>import javax.servlet.annotation.WebServlet;<br/>import javax.servlet.http.HttpServlet;<br/>import javax.servlet.http.HttpServletRequest;<br/>import javax.servlet.http.HttpServletResponse;<br/><br/>@WebServlet(description = &quot;图片验证码生成&quot;, urlPatterns = { &quot;/ImageServlet&quot; })<br/>public class ImageServlet extends HttpServlet {<br/> &nbsp; &nbsp;private static final long serialVersionUID = 1L;<br/><br/> &nbsp; &nbsp;public ImageServlet() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;super();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;response.setContentType(&quot;image/jpeg&quot;);// 设置相应类型,告诉浏览器输出的内容为图片<br/> &nbsp; &nbsp; &nbsp; &nbsp;response.setHeader(&quot;Pragma&quot;, &quot;No-cache&quot;);// 设置响应头信息，告诉浏览器不要缓存此内容<br/> &nbsp; &nbsp; &nbsp; &nbsp;response.setHeader(&quot;Cache-Control&quot;, &quot;no-cache&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;response.setDateHeader(&quot;Expire&quot;, 0);<br/> &nbsp; &nbsp; &nbsp; &nbsp;Captcha randomValidateCode = new Captcha();<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;randomValidateCode.getRandcode(request, response);// 输出图片方法<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;doGet(request, response);<br/> &nbsp; &nbsp;}<br/>}<br/></span></code></pre><p><br/></p>','2015-08-07 02:51:49','2015-08-07 02:51:49','5568000980689df542ea01f6','1','验证码图片生成工具，使用JAVA生成的图片验证码，调用getRandcode方法获取图片验证码，以流的方式传输到前端页面。',1,NULL,1),('55c41fbca643aee46fc477fc','文件相关操作工具类——FileUtils.java','<p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">文件相关操作的工具类，创建文件、删除文件、删除目录、复制、移动文件、获取文件路径、获取目录下文件个数等，满足大多数系统需求。</span></p><p><br/></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">源码如下：（点击下载</span> <img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(247, 150, 70); text-decoration: underline;\" href=\"/resources/attached/file/FileUtils.java\" title=\"FileUtils.java\"><span style=\"color: rgb(247, 150, 70);\">FileUtils.java</span></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">）</span><br/></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">import java.io.BufferedReader;<br/>import java.io.BufferedWriter;<br/>import java.io.File;<br/>import java.io.FileInputStream;<br/>import java.io.FileNotFoundException;<br/>import java.io.FileOutputStream;<br/>import java.io.FileReader;<br/>import java.io.FileWriter;<br/>import java.io.IOException;<br/>import java.io.InputStream;<br/>import java.io.Serializable;<br/>import java.nio.CharBuffer;<br/>import java.nio.MappedByteBuffer;<br/>import java.nio.channels.FileChannel;<br/>import java.nio.charset.Charset;<br/>import java.nio.charset.CharsetDecoder;<br/>import java.text.SimpleDateFormat;<br/>import java.util.ArrayList;<br/>import java.util.Date;<br/>import java.util.HashMap;<br/>import java.util.List;<br/>import java.util.regex.Pattern;<br/><br/>/**<br/> * 用于文件相关操作的工具类<br/> * <br/> * 作者: zhoubang 日期：2015年8月7日 上午10:55:15<br/> */<br/>public final class FileUtils implements Serializable {<br/> &nbsp; &nbsp;private static final long serialVersionUID = 6841417839693317734L;<br/><br/> &nbsp; &nbsp;private FileUtils() {<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 得到文件的输入流，如无法定位文件返回null。<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param relativePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件相对当前应用程序的类加载器的路径。<br/> &nbsp; &nbsp; * @return 文件的输入流。<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static InputStream getResourceStream(String relativePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return Thread.currentThread().getContextClassLoader().getResourceAsStream(relativePath);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 关闭输入流。<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param is 输入流，可以是null。<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void closeInputStream(InputStream is) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (is != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static void closeFileOutputStream(FileOutputStream fos) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fos != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fos.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 从文件路径中提取目录路径，如果文件路径不含目录返回null。<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath 文件路径。<br/> &nbsp; &nbsp; * @return 目录路径，不以&#39;/&#39;或操作系统的文件分隔符结尾。<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String extractDirPath(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;int separatePos = Math.max(filePath.lastIndexOf(&#39;/&#39;), filePath.lastIndexOf(&#39;\\\\&#39;)); // 分隔目录和文件名的位置<br/> &nbsp; &nbsp; &nbsp; &nbsp;return separatePos == -1 ? null : filePath.substring(0, separatePos);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 从文件路径中提取文件名, 如果不含分隔符返回null<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * @return 文件名, 如果不含分隔符返回null<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String extractFileName(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;int separatePos = Math.max(filePath.lastIndexOf(&#39;/&#39;), filePath.lastIndexOf(&#39;\\\\&#39;)); // 分隔目录和文件名的位置<br/> &nbsp; &nbsp; &nbsp; &nbsp;return separatePos == -1 ? null : filePath.substring(separatePos + 1, filePath.length());<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 按路径建立文件，如已有相同路径的文件则不建立。<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath 要建立文件的路径。<br/> &nbsp; &nbsp; * @return 表示此文件的File对象。<br/> &nbsp; &nbsp; * @throws IOException 如路径是目录或建文件时出错抛异常。<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static File makeFile(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (file.isFile())<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return file;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (filePath.endsWith(&quot;/&quot;) || filePath.endsWith(&quot;\\\\&quot;))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new IOException(filePath + &quot; is a directory&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;String dirPath = extractDirPath(filePath); // 文件所在目录的路径<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (dirPath != null) { // 如文件所在目录不存在则先建目录<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;makeFolder(dirPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;file.createNewFile();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Folder has been created: &quot; + filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// System.out.println(&quot;文件已创建: &quot; + filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return file;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 新建目录,支持建立多级目录<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param folderPath 新建目录的路径字符串<br/> &nbsp; &nbsp; * @return boolean,如果目录创建成功返回true,否则返回false<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean makeFolder(String folderPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File myFilePath = new File(folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!myFilePath.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;myFilePath.mkdirs();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// System.out.println(&quot;新建目录为：&quot; + folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Create new folder：&quot; + folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// System.out.println(&quot;目录已经存在: &quot; + folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Folder is existed：&quot; + folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// System.out.println(&quot;新建目录操作出错&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.error(&quot;Create new folder error: &quot; + folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 删除文件<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePathAndName 要删除文件名及路径<br/> &nbsp; &nbsp; * @return boolean 删除成功返回true,删除失败返回false<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean deleteFile(String filePathAndName) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File myDelFile = new File(filePathAndName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (myDelFile.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;myDelFile.delete();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;File：&quot; + filePathAndName +<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &quot; has been deleted!!!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.error(&quot;Error delete file：&quot; + filePathAndName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 递归删除指定目录中所有文件和子文件夹<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param path<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;某一目录的路径,如&quot;c:\\cs&quot;<br/> &nbsp; &nbsp; * @param ifDeleteFolder<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boolean值,如果传true,则删除目录下所有文件和文件夹;如果传false,则只删除目录下所有文件,子文件夹将保留<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void deleteAllFile(String path, boolean ifDeleteFolder) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(path);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!file.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;String[] tempList = file.list();<br/> &nbsp; &nbsp; &nbsp; &nbsp;String temp = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempList.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (path.endsWith(&quot;\\\\&quot;) || path.endsWith(&quot;/&quot;))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;temp = path + tempList[i];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;temp = path + File.separator + tempList[i];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((new File(temp)).isFile()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deleteFile(temp);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if ((new File(temp)).isDirectory() &amp;&amp; ifDeleteFolder) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deleteAllFile(path + File.separator + tempList[i], ifDeleteFolder);// 先删除文件夹里面的文件<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deleteFolder(path + File.separator + tempList[i]);// 再删除空文件夹<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 删除文件夹,包括里面的文件<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param folderPath 文件夹路径字符串<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void deleteFolder(String folderPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File myFilePath = new File(folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (myFilePath.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deleteAllFile(folderPath, true); // 删除完里面所有内容<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;myFilePath.delete(); // 删除空文件夹<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;ok!Delete folder success: &quot; + folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.error(&quot;Delete folder fail: &quot; + folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 复制文件,如果目标文件的路径不存在,会自动新建路径<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param sourcePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;源文件路径, e.g. &quot;c:/cs.txt&quot;<br/> &nbsp; &nbsp; * @param targetPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件路径 e.g. &quot;f:/bb/cs.txt&quot;<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void copyFile(String sourcePath, String targetPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream inStream = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;FileOutputStream fos = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int byteSum = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int byteRead = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File sourcefile = new File(sourcePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (sourcefile.exists()) { // 文件存在时<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inStream = new FileInputStream(sourcePath); // 读入原文件<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String dirPath = extractDirPath(targetPath); // 文件所在目录的路径<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (dirPath != null) { // 如文件所在目录不存在则先建目录<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;makeFolder(dirPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fos = new FileOutputStream(targetPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;byte[] buffer = new byte[1444];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ((byteRead = inStream.read(buffer)) != -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;byteSum += byteRead; // 字节数 文件大小<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fos.write(buffer, 0, byteRead);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;File size is: &quot; + byteSum);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Source path is --&gt;&quot; + sourcePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Target path is--&gt;&quot; + targetPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;File size is--&gt;&quot; + byteSum);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.debug(&quot;Copy single file fail: &quot; + sourcePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;closeInputStream(inStream);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;closeFileOutputStream(fos);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将路径和文件名拼接起来<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param folderPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;某一文件夹路径字符串，e.g. &quot;c:\\cs\\&quot; 或 &quot;c:\\cs&quot;<br/> &nbsp; &nbsp; * @param fileName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;某一文件名字符串, e.g. &quot;cs.txt&quot;<br/> &nbsp; &nbsp; * @return 文件全路径的字符串<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String makeFilePath(String folderPath, String fileName) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return folderPath.endsWith(&quot;\\\\&quot;) || folderPath.endsWith(&quot;/&quot;) ? folderPath + fileName : folderPath + File.separatorChar + fileName;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 将某一文件夹下的所有文件和子文件夹拷贝到目标文件夹，若目标文件夹不存在将自动创建<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param sourcePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;源文件夹字符串，e.g. &quot;c:\\cs&quot;<br/> &nbsp; &nbsp; * @param targetPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标文件夹字符串，e.g. &quot;d:\\tt\\qq&quot;<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;unused&quot;)<br/> &nbsp; &nbsp;public static void copyFolder(String sourcePath, String targetPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;FileInputStream input = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;FileOutputStream output = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;makeFolder(targetPath); // 如果文件夹不存在 则建立新文件夹<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String[] file = new File(sourcePath).list();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File temp = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; file.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String tempPath = makeFilePath(sourcePath, file[i]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;temp = new File(tempPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String target = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (temp.isFile()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input = new FileInputStream(temp);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output = new FileOutputStream(target = makeFilePath(targetPath, file[i]));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;byte[] b = new byte[1024 * 5];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int len = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int sum = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ((len = input.read(b)) != -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output.write(b, 0, len);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum += len;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;target = target + &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output.flush();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;closeInputStream(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;closeFileOutputStream(output);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Source path--&gt;&quot; + tempPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Target path--&gt;&quot; + target);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;File size--&gt;&quot; + sum);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (temp.isDirectory()) {// 如果是子文件夹<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;copyFolder(sourcePath + &#39;/&#39; + file[i], targetPath + &#39;/&#39; + file[i]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Copy all the folder fail!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;closeInputStream(input);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;closeFileOutputStream(output);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 移动文件<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param oldFilePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;旧文件路径字符串, e.g. &quot;c:\\tt\\cs.txt&quot;<br/> &nbsp; &nbsp; * @param newFilePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新文件路径字符串, e.g. &quot;d:\\kk\\cs.txt&quot;<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void moveFile(String oldFilePath, String newFilePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;copyFile(oldFilePath, newFilePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;deleteFile(oldFilePath);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 移动文件夹<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param oldFolderPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;旧文件夹路径字符串，e.g. &quot;c:\\cs&quot;<br/> &nbsp; &nbsp; * @param newFolderPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;新文件夹路径字符串，e.g. &quot;d:\\cs&quot;<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void moveFolder(String oldFolderPath, String newFolderPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;copyFolder(oldFolderPath, newFolderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;deleteFolder(oldFolderPath);<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得某一文件夹下的所有文件的路径集合<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件夹路径<br/> &nbsp; &nbsp; * @return ArrayList，其中的每个元素是一个文件的路径的字符串<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static ArrayList&lt;String&gt; getFilePathFromFolder(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;ArrayList&lt;String&gt; fileNames = new ArrayList&lt;String&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File[] tempFile = file.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempFile.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].isFile()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String tempFileName = tempFile[i].getName();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fileNames.add(makeFilePath(filePath, tempFileName));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// fileNames.add(&quot;尚无文件到达！&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Can not find files!&quot;+e.getMessage());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return fileNames;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 递归遍历文件目录,获取所有文件路径<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * @return 2012-1-4<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static ArrayList&lt;String&gt; getAllFilePathFromFolder(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;ArrayList&lt;String&gt; filePaths = new ArrayList&lt;String&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File[] tempFile = file.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempFile.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String tempFileName = tempFile[i].getName();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String path = makeFilePath(filePath, tempFileName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].isFile()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filePaths.add(path);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ArrayList&lt;String&gt; tempFilePaths = getAllFilePathFromFolder(path);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFilePaths.size() &gt; 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (String tempPath : tempFilePaths) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filePaths.add(tempPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// fileNames.add(&quot;尚无文件到达！&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;Can not find files!&quot;+e.getMessage());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return filePaths;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得某一文件夹下的所有TXT，txt文件名的集合<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件夹路径<br/> &nbsp; &nbsp; * @return ArrayList，其中的每个元素是一个文件名的字符串<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings(&quot;rawtypes&quot;)<br/> &nbsp; &nbsp;public static ArrayList getFileNameFromFolder(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;ArrayList&lt;String&gt; fileNames = new ArrayList&lt;String&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;File[] tempFile = file.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempFile.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].isFile())<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fileNames.add(tempFile[i].getName());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return fileNames;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得某一文件夹下的所有文件的总数<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件夹路径<br/> &nbsp; &nbsp; * @return int 文件总数<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int getFileCount(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;int count = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!isFolderExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return count;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File[] tempFile = file.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempFile.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].isFile())<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count++;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception fe) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return count;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得某一路径下要求匹配的文件的个数<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件夹路径<br/> &nbsp; &nbsp; * @param matchs<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;需要匹配的文件名字符串,如&quot;.*a.*&quot;,如果传空字符串则不做匹配工作 直接返回路径下的文件个数<br/> &nbsp; &nbsp; * @return int 匹配文件名的文件总数<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int getFileCount(String filePath, String matchs) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;int count = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isFolderExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return count;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (matchs.equals(&quot;&quot;) || matchs == null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return getFileCount(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;filePath in getFileCount: &quot; + filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;matchs in getFileCount: &quot; + matchs);<br/> &nbsp; &nbsp; &nbsp; &nbsp;File[] tempFile = file.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempFile.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].isFile())<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (Pattern.matches(matchs, tempFile[i].getName()))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count++;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return count;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;public static int getStrCountFromFile(String filePath, String str) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isFileExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;FileReader fr = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedReader br = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;int count = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fr = new FileReader(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;br = new BufferedReader(fr);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String line = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ((line = br.readLine()) != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (line.indexOf(str) != -1)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count++;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (br != null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;br.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (fr != null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fr.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return count;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得某一文件的行数<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件夹路径<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @return int 行数<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static int getFileLineCount(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isFileExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;FileReader fr = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedReader br = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;int count = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fr = new FileReader(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;br = new BufferedReader(fr);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ((br.readLine()) != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count++;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (FileNotFoundException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (br != null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;br.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (fr != null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fr.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return count;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 判断某一文件是否为空<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath 文件的路径字符串，e.g. &quot;c:\\cs.txt&quot;<br/> &nbsp; &nbsp; * @return 如果文件为空返回true, 否则返回false<br/> &nbsp; &nbsp; * @throws IOException<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean ifFileIsNull(String filePath) throws IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;boolean result = false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;FileReader fr = new FileReader(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fr.read() == -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result = true;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(filePath + &quot; is null!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(filePath + &quot; not null!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;fr.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp;return result;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 判断文件是否存在<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param fileName 文件路径字符串，e.g. &quot;c:\\cs.txt&quot;<br/> &nbsp; &nbsp; * @return 若文件存在返回true,否则返回false<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isFileExist(String fileName) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 判断文件名是否为空<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fileName == null || fileName.length() == 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.error(&quot;File length is 0!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读入文件 判断文件是否存在<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(fileName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists() || file.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.error(fileName + &quot;is not exist!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 判断文件夹是否存在<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param folderPath 文件夹路径字符串，e.g. &quot;c:\\cs&quot;<br/> &nbsp; &nbsp; * @return 若文件夹存在返回true, 否则返回false<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isFolderExist(String folderPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return file.isDirectory() ? true : false;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得文件的大小<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath 文件路径字符串，e.g. &quot;c:\\cs.txt&quot;<br/> &nbsp; &nbsp; * @return 返回文件的大小,单位kb,如果文件不存在返回null<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Double getFileSize(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isFileExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double intNum = Math.ceil(file.length() / 1024.0);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new Double(intNum);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得文件的大小,字节表示<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath 文件路径字符串，e.g. &quot;c:\\cs.txt&quot;<br/> &nbsp; &nbsp; * @return 返回文件的大小,单位kb,如果文件不存在返回null<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Double getFileByteSize(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isFileExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double intNum = Math.ceil(file.length());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new Double(intNum);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得外汇牌价文件的大小(字节)<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath 文件路径字符串，e.g. &quot;c:\\cs.txt&quot;<br/> &nbsp; &nbsp; * @return 返回文件的大小,单位kb,如果文件不存在返回null<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static Double getWhpjFileSize(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isFileExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new Double(file.length());<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得文件的最后修改时间<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath 文件路径字符串，e.g. &quot;c:\\cs.txt&quot;<br/> &nbsp; &nbsp; * @return 返回文件最后的修改日期的字符串,如果文件不存在返回null<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static String fileModifyTime(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!isFileExist(filePath))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;long timeStamp = file.lastModified();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SimpleDateFormat formatter = new SimpleDateFormat(&quot;yyyy/MM/dd HH:mm&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String tsForm = formatter.format(new Date(timeStamp));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return tsForm;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 遍历某一文件夹下的所有文件,返回一个ArrayList,每个元素又是一个子ArrayList,<br/> &nbsp; &nbsp; * 子ArrayList包含三个字段,依次是文件的全路径(String),文件的修改日期(String), 文件的大小(Double)<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param folderPath 某一文件夹的路径<br/> &nbsp; &nbsp; * @return ArrayList<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })<br/> &nbsp; &nbsp;public static ArrayList getFilesSizeModifyTime(String folderPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;List returnList = new ArrayList();<br/> &nbsp; &nbsp; &nbsp; &nbsp;List filePathList = getFilePathFromFolder(folderPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; filePathList.size(); i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List tempList = new ArrayList();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String filePath = (String) filePathList.get(i);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String modifyTime = FileUtils.fileModifyTime(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Double fileSize = FileUtils.getFileSize(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempList.add(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempList.add(modifyTime);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempList.add(fileSize);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;returnList.add(tempList);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return (ArrayList) returnList;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得某一文件夹下的所有TXT，txt文件名的集合<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件夹路径<br/> &nbsp; &nbsp; * @return ArrayList，其中的每个元素是一个文件名的字符串<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })<br/> &nbsp; &nbsp;public static ArrayList getTxtFileNameFromFolder(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;ArrayList fileNames = new ArrayList();<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;File[] tempFile = file.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempFile.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].isFile())<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].getName().indexOf(&quot;TXT&quot;) != -1 || tempFile[i].getName().indexOf(&quot;txt&quot;) != -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fileNames.add(tempFile[i].getName());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return fileNames;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 获得某一文件夹下的所有xml，XML文件名的集合<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;文件夹路径<br/> &nbsp; &nbsp; * @return ArrayList，其中的每个元素是一个文件名的字符串<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })<br/> &nbsp; &nbsp;public static ArrayList getXmlFileNameFromFolder(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;ArrayList fileNames = new ArrayList();<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;File[] tempFile = file.listFiles();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; tempFile.length; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].isFile())<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tempFile[i].getName().indexOf(&quot;XML&quot;) != -1 || tempFile[i].getName().indexOf(&quot;xml&quot;) != -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fileNames.add(tempFile[i].getName());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return fileNames;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 校验文件是否存在<br/> &nbsp; &nbsp; *<br/> &nbsp; &nbsp; * @param fileName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String 文件名称<br/> &nbsp; &nbsp; * @param mapErrorMessage<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Map 错误信息Map集<br/> &nbsp; &nbsp; * @return boolean 校验值<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })<br/> &nbsp; &nbsp;public static boolean checkFile(String fileName, HashMap mapErrorMessage) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (mapErrorMessage == null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mapErrorMessage = new HashMap();<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 判断文件名是否为空<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fileName == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fileName = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 判断文件名长度是否为0<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fileName.length() == 0) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mapErrorMessage.put(&quot;errorMessage&quot;, &quot;fileName length is 0&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读入文件 判断文件是否存在<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(fileName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists() || file.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mapErrorMessage.put(&quot;errorMessage&quot;, fileName + &quot;is not exist!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 校验文件是否存在 add by fzhang<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param fileName<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String 文件名称<br/> &nbsp; &nbsp; * @return boolean 校验值<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean checkFile(String fileName) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 判断文件名是否为空<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fileName == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fileName = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 判断文件名长度是否为0<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (fileName.length() == 0) {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(&quot;File name length is 0.&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读入文件 判断文件是否存在<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(fileName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists() || file.isDirectory()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(fileName +&quot;is not exist!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 新建目录<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param folderPath<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String 如 c:/fqf<br/> &nbsp; &nbsp; * @return boolean<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void newFolder(String folderPath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String filePath = folderPath;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filePath = filePath.toString();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;java.io.File myFilePath = new java.io.File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!myFilePath.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;myFilePath.mkdir();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;新建目录操作出错&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 重新缓存发送失败的缓存文件<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @author Herman.Xiong<br/> &nbsp; &nbsp; * @throws IOException<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;@SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })<br/> &nbsp; &nbsp;public static void sessionData(String path, List&lt;List&gt; list)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throws IOException {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;BufferedWriter bw = new BufferedWriter(new FileWriter(path));<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;for (List&lt;String&gt; tempList : list) {<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (String str : tempList) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (str != null &amp;&amp; !str.equals(&quot;&quot;)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bw.write(str);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bw.newLine();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bw.flush();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;bw.close();<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 在指定的文本中对比数据<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param urladdr<br/> &nbsp; &nbsp; * @param filePath<br/> &nbsp; &nbsp; * @return boolean<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean compareUrl(String urladdr, String filePath, FileChannel fc) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;boolean isExist = false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;Charset charset = Charset.forName(&quot;UTF-8&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;CharsetDecoder decoder = charset.newDecoder();<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int sz = (int) fc.size();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CharBuffer cb = decoder.decode(bb);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String s = String.valueOf(cb);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int n = s.indexOf(urladdr);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (n &gt; -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.info(filePath + &quot; the article already exists &quot; +<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// urladdr);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;isExist = true;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.error(&quot;document alignment error&quot; + e);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// if(!Util.isEmpty(fc))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// fc.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// }<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// if(!Util.isEmpty(fis))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// fis.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// }<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e2) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// log4j.error(e2);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return isExist;<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/></span></code></pre><p><br/></p>','2015-08-07 03:02:21','2015-08-07 03:02:21','5568000980689df542ea01f6','1','文件相关操作的工具类，创建文件、删除文件、删除目录、复制、移动文件、获取文件路径、获取目录下文件个数等，满足大多数系统需求。',1,NULL,1),('55c425cda643aee470c477fc','JAVA多线程下载网络文件','<p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">JAVA多线程下载网络文件，开启多个线程，同时下载网络文件。</span></p><p><br/></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">源码如下：（点击下载</span> <img alt=\"\" title=\"\" style=\"vertical-align: middle; margin-right: 2px; width: 0px; height: 0px;\" src=\"http://kdgx.v084.10000net.cn/resources/ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif\" height=\"0\" border=\"0\" vspace=\"0\" width=\"0\"/><a style=\"font-size: 12px; color: rgb(247, 150, 70); text-decoration: underline;\" href=\"/resources/attached/file/MultiThreadDownload.java\" title=\"MultiThreadDownload.java\"><span style=\"color: rgb(247, 150, 70);\">MultiThreadDownload.java</span></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">）</span><br/></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">import java.io.InputStream;<br/>import java.io.RandomAccessFile;<br/>import java.net.HttpURLConnection;<br/>import java.net.URL;<br/><br/>/**<br/> * 说明：<br/> * 每一个线程下载的位置计算方式：<br/> * 开始位置： (线程id - 1) * 每一块大小<br/> * 结束位置： (线程id*每一块大小) - 1 <br/> * <br/> * 注意：有时候不一定能够整除，所以最后一个线程的结束位置应该是文件的末尾<br/> * &nbsp;<br/> * &nbsp;步骤：<br/> * &nbsp;1.本地创建一个大小跟服务器文件相同的临时文件<br/> * &nbsp;2.计算分配几个线程去下载服务器上的资源，知道每个线程下载文件的位置<br/> * &nbsp;3.开启三个线程，每一个线程下载对应位置的文件<br/> * &nbsp;4.如果所有的线程，都把自己的数据下载完毕后，服务器上的资源都被下载到本地了<br/> * <br/> * 作者: zhoubang <br/> * 日期：2015年8月7日 上午11:20:06<br/> */<br/>public class MultiThreadDownload {<br/> &nbsp; &nbsp;public static String path = &quot;http://static.csdn.net/public/common/toolbar/css/index.css&quot;; // 要下载的网络资源文件路径<br/> &nbsp; &nbsp;public static int threadCount = 10; // 开启的线程数<br/> &nbsp; &nbsp;public static int runningThread = 10; // 记录已经运行的线程数量<br/> &nbsp; &nbsp;public static long startTime;<br/><br/> &nbsp; &nbsp;private static final String filePath = &quot;f:\\\\index.css&quot;; //文件存放本地的路径<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 测试下载<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * 作者: zhoubang <br/> &nbsp; &nbsp; * 日期：2015年8月7日 上午11:16:23<br/> &nbsp; &nbsp; * @param args<br/> &nbsp; &nbsp; * @throws Exception<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void main(String[] args) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;startTime = System.currentTimeMillis();<br/> &nbsp; &nbsp; &nbsp; &nbsp;// 1.连接服务器，获取一个文件，获取文件的长度，在本地创建一个跟服务器一样大小的临时文件<br/> &nbsp; &nbsp; &nbsp; &nbsp;URL url = new URL(path);<br/> &nbsp; &nbsp; &nbsp; &nbsp;HttpURLConnection conn = (HttpURLConnection) url.openConnection();<br/> &nbsp; &nbsp; &nbsp; &nbsp;conn.setConnectTimeout(5000);<br/> &nbsp; &nbsp; &nbsp; &nbsp;conn.setRequestMethod(&quot;GET&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;int code = conn.getResponseCode();<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (code == 200) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 服务器端返回的数据的长度，实际上就是文件的长度<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int length = conn.getContentLength();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;文件总长度：&quot; + length);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 在客户端本地创建出来一个大小跟服务器端一样大小的临时文件<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RandomAccessFile raf = new RandomAccessFile(filePath, &quot;rwd&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 指定创建的这个文件的长度<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raf.setLength(length);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raf.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 假设是3个线程去下载资源。<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 平均每一个线程下载的文件大小.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int blockSize = length / threadCount;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int threadId = 1; threadId &lt;= threadCount; threadId++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 第一个线程下载的开始位置<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int startIndex = (threadId - 1) * blockSize;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int endIndex = threadId * blockSize - 1;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (threadId == threadCount) {// 最后一个线程下载的长度要稍微长一点<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;endIndex = length;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;线程：&quot; + threadId + &quot;下载:---&quot; + startIndex + &quot;---&gt;&quot; + endIndex);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new DownLoadThread(path, threadId, startIndex, endIndex).start();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.printf(&quot;服务器错误!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 下载文件的子线程，每一个线程下载对应位置的文件<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * 作者: zhoubang <br/> &nbsp; &nbsp; * 日期：2015年8月7日 上午11:16:34<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static class DownLoadThread extends Thread {<br/> &nbsp; &nbsp; &nbsp; &nbsp;private int threadId;<br/> &nbsp; &nbsp; &nbsp; &nbsp;private int startIndex;<br/> &nbsp; &nbsp; &nbsp; &nbsp;private int endIndex;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; &nbsp; &nbsp; * @param path<br/> &nbsp; &nbsp; &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;下载文件在服务器上的路径<br/> &nbsp; &nbsp; &nbsp; &nbsp; * @param threadId<br/> &nbsp; &nbsp; &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;线程Id<br/> &nbsp; &nbsp; &nbsp; &nbsp; * @param startIndex<br/> &nbsp; &nbsp; &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;线程下载的开始位置<br/> &nbsp; &nbsp; &nbsp; &nbsp; * @param endIndex<br/> &nbsp; &nbsp; &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;线程下载的结束位置<br/> &nbsp; &nbsp; &nbsp; &nbsp; */<br/> &nbsp; &nbsp; &nbsp; &nbsp;public DownLoadThread(String path, int threadId, int startIndex, int endIndex) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.threadId = threadId;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.startIndex = startIndex;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.endIndex = endIndex;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;@Override<br/> &nbsp; &nbsp; &nbsp; &nbsp;public void run() {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;URL url = new URL(path);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpURLConnection conn = (HttpURLConnection) url.openConnection();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conn.setConnectTimeout(5000);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conn.setRequestMethod(&quot;GET&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 重要:请求服务器下载部分文件 指定文件的位置<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conn.setRequestProperty(&quot;Range&quot;, &quot;bytes=&quot; + startIndex + &quot;-&quot; + endIndex);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 从服务器请求全部资源返回200 ok如果从服务器请求部分资源 返回 206 ok<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int code = conn.getResponseCode();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;code:&quot; + code);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InputStream is = conn.getInputStream();// 已经设置了请求的位置，返回的是当前位置对应的文件的输入流<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RandomAccessFile raf = new RandomAccessFile(filePath, &quot;rwd&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 随机写文件的时候从哪个位置开始写<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raf.seek(startIndex);// 定位文件<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int len = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;byte[] buffer = new byte[1024];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ((len = is.read(buffer)) != -1) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raf.write(buffer, 0, len);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raf.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;线程：&quot; + threadId + &quot;下载完毕&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println((System.currentTimeMillis() - startTime));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;runningThread--;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (runningThread == 0) {// 所有的线程执行完毕<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;文件全部下载完毕!&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;}<br/>}<br/></span></code></pre><p><br/></p>','2015-08-07 03:28:14','2015-08-07 03:28:14','55631ee26ec09df591a730ed','1','JAVA多线程下载网络文件，开启多个线程，同时下载网络文件。',1,NULL,1),('55c44504a643aee471c477fc','HTML5+CSS3鼠标悬停图片特效','<p style=\"line-height: 16px;\"><img alt=\"1.jpg\" src=\"/resources/attached/image/201508071438925648152042056.jpg\" title=\"201508071438925648152042056.jpg\"/></p><p><br/></p><p style=\"line-height: 16px;\"><a style=\"text-decoration: underline;\" title=\"HTML5+CSS3鼠标悬停图片特效\" target=\"_blank\" href=\"/resources/demoSources/css3Img/index1.html\"><span style=\"font-size: 18px; color: rgb(255, 0, 0);\"><strong>点击预览效果</strong></span></a><span style=\"color: rgb(0, 176, 80); font-size: 18px;\"><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong></span><span style=\"color: rgb(0, 176, 80); font-size: 14px;\"><strong>下载该特效：</strong></span> <img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"font-size:12px; color:#0066cc;\" href=\"http://www.2b2b92b.com/resources/attached/file/HTML5+CSS3鼠标悬停图片特效.zip\" title=\"HTML5+CSS3鼠标悬停图片特效.zip\">HTML5+CSS3鼠标悬停图片特效.zip</a></p><p style=\"line-height: 16px;\"><a style=\"font-size:12px; color:#0066cc;\" href=\"http://www.2b2b92b.com/resources/attached/file/HTML5+CSS3鼠标悬停图片特效.zip\" title=\"HTML5+CSS3鼠标悬停图片特效.zip\"><br/></a></p><p></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">特效说明：</span></p><p><span style=\"font-size: 14px;\">一款HTML5+CSS3鼠标悬停图片事件网页特效，集合了最流行鼠标悬停图片文字、图片动画移动、渐隐渐显动画特效。</span></p><p><span style=\"font-size: 14px;\">请用支持HTML5+CSS3主流浏览器预览效果。（兼容测试：FireFox、Chrome、Safari、Opera等支持HTML5/CSS3浏览器）</span></p><p><br/></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">使用方法：</span><span style=\"font-size: 14px;\"><br/>1、调用CSS样式：<br/>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/normalize.css&quot; /&gt;<br/>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/demo.css&quot; /&gt;<br/><br/>2、必要样式：<br/>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/set1.css&quot; /&gt;<br/><br/>3、添加HTML代码：<br/>将&lt;!--效果html开始--&gt;......&lt;!--效果html结束--&gt;之间的html和js代码；放在&lt;body&gt;&lt;/body&gt;之间。 <br/></span></p><p><span style=\"font-size: 14px;\"><br/></span></p>','2015-08-07 05:41:24','2015-08-07 05:41:24','5','1','一款HTML5+CSS3鼠标悬停图片事件网页特效，集合了最流行鼠标悬停图片文字、图片动画移动、渐隐渐显动画特效。',1,NULL,1),('55dbcd2692eaf20c54d24e8b','linux删除某类型文件的命令','<p><span style=\"font-size: 14px;\">使用linux命令行，删除某目录下某类型的文件，如：删除.rar结尾的所有文件。</span></p><p><br/></p><p><span style=\"font-size: 14px;\">命令如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">find . -name &quot;*.rar&quot; -type f -print -exec rm -rf {} \\;<br/></span></code></pre><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">说明：命令中出现的 *.rar替换成你想删除的类型即可。</span></p><p><br/></p><p><br/></p>','2015-08-25 10:04:22','2015-08-25 10:04:22','55dbcbe592eaf20c53d24e8b','1','linux删除某类型文件的命令，在命令行输入即可。',1,NULL,1),('55dbcf4092eaf20c55d24e8b','nginx处理静态资源的配置','<p><span style=\"font-size: 14px;\">修改nginx.conf文件，用于nginx处理静态资源。</span></p><p><br/></p><p></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">主要配置如下(在server配置中加入location配置即可)：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">server {<br/> &nbsp; &nbsp;listen &nbsp; &nbsp; &nbsp; 80;<br/> &nbsp; &nbsp;server_name &nbsp;123.57.162.75;<br/> &nbsp; &nbsp;charset utf-8;<br/> &nbsp; &nbsp;index index.html index.htm index.jsp index.do;<br/> &nbsp; &nbsp;root /opt/nginx-1.4.7/html/resources;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;#配置Nginx动静分离，定义的静态页面直接从Nginx发布目录读取。<br/> &nbsp; &nbsp;location ~ .*\\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ <br/> &nbsp; &nbsp;{ <br/> &nbsp; &nbsp; &nbsp; &nbsp;root /opt/nginx-1.4.7/html/resources;<br/> &nbsp; &nbsp; &nbsp; &nbsp;#expires定义用户浏览器缓存的时间为7天，如果静态页面不常更新，可以设置更长，这样可以节省带宽和缓解服务器的压力<br/> &nbsp; &nbsp; &nbsp; &nbsp;expires &nbsp; &nbsp; &nbsp;7d; <br/> &nbsp; &nbsp;} <br/>}<br/></span></code></pre><p><br/></p>','2015-08-25 10:13:21','2015-08-25 10:13:21','11','1','修改nginx.conf文件，用于nginx处理静态资源。',1,NULL,1),('55fa645fea01f20c435bb66c','HTTP状态码——对照表','<p><span style=\"color: rgb(0, 176, 80);\"><strong><span style=\"font-size: 14px;\">ASCII码介绍：<br/><br/>HTTP状态码（HTTP Status Code）用来表示web服务器响应客户端的HTTP状态。主要有一下5种状态类型。<br/>1xx&nbsp;&nbsp;&nbsp; 消息<br/>2xx&nbsp;&nbsp;&nbsp; 成功<br/>3xx&nbsp;&nbsp;&nbsp; 重定向<br/>4xx&nbsp;&nbsp;&nbsp; 客户端错误<br/>5xx&nbsp;&nbsp;&nbsp; 服务器错误</span></strong></span><br/></p><p><br/></p><table interlaced=\"enabled\" class=\"sortEnabled\" data-sort=\"sortEnabled\" style=\"border: 0px none;\"><tbody><tr class=\"ue-table-interlace-color-single firstRow\"><td style=\"border-left-color: rgb(255, 255, 255); border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-top-width: 1px; word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"middle\" width=\"69\" align=\"center\"><span style=\"font-size: 14px;\"><strong>状态码</strong></span><br/></td><td style=\"border-left-color: rgb(255, 255, 255); border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-top-width: 1px; word-break: break-all;\" rowspan=\"1\" colspan=\"1\" valign=\"middle\" width=\"1045\" align=\"center\"><strong><span style=\"font-size: 14px;\">含义</span></strong><br/></td></tr><tr class=\"ue-table-interlace-color-double\" style=\"height:padding-top:5px;\"><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"69\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">100<br/></span></p></td><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">客户端应当继续发送请求。这个临时响应是用来通知客户端它的部分请求已经被服务器接收，且仍未被拒绝。客户端应当继续发送请求的剩余部分，或者如果请求已经完成，忽略这个响应。服务器必须在请求完成后向客户端发送一个最终响应。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">101<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器已经理解了客户端的请求，并将通过Upgrade 消息头通知客户端采用不同的协议来完成这个请求。在发送完这个响应最后的空行后，服务器将会切换到在Upgrade 消息头中定义的那些协议。只有在切换新的协议更有好处的时候才应该采取类似措施。例如，切换到新的HTTP 版本比旧版本更有优势，或者切换到一个实时且同步的协议以传送利用此类特性的资源。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">102<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">由WebDAV（RFC 2518）扩展的状态码，代表处理将被继续执行。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">200<br/></span></p></td><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求已成功，请求所希望的响应头或数据体将随此响应返回。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">201<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求已经被实现，而且有一个新的资源已经依据请求的需要而建立，且其 URI 已经随Location 头信息返回。假如需要的资源无法及时建立的话，应当返回 &#39;202 Accepted&#39;。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">202<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器已接受请求，但尚未处理。正如它可能被拒绝一样，最终该请求可能会也可能不会被执行。在异步操作的场合下，没有比发送这个状态码更方便的做法了。返回202状态码的响应的目的是允许服务器接受其他过程的请求（例如某个每天只执行一次的基于批处理的操作），而不必让客户端一直保持与服务器的连接\n直到批处理操作全部完成。在接受请求处理并返回202状态码的响应应当在返回的实体中包含一些指示处理当前状态的信息，以及指向处理状态监视器或状态预测\n的指针，以便用户能够估计操作是否已经完成。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">203<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器已成功处理了请求，但返回的实体头部元信息不是在原始服务器上有效的确定集合，而是来自本地或者第三方的拷贝。当前的信息可能是原始版本的子集或者\n超集。例如，包含资源的元数据可能导致原始服务器知道元信息的超级。使用此状态码不是必须的，而且只有在响应不使用此状态码便会返回200\n &nbsp; &nbsp; &nbsp; &nbsp;OK的情况下才是合适的。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">204<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器成功处理了请求，但不需要返回任何实体内容，并且希望返回更新了的元信息。响应可能通过实体头部的形式，返回新的或更新后的元信息。如果存在这些头部信息，则应当与所请求的变量相呼应。如果客户端是浏览器的话，那么用户浏览器应保留发送了该请求的页面，而不产生任何文档视图上的变化，即使按照规范新的或更新后的元信息应当被应用到用户浏览器活动视图中的文档。&nbsp;\n 由于204响应被禁止包含任何消息体，因此它始终以消息头后的第一个空行结尾。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">205<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器成功处理了请求，且没有返回任何内容。但是与204响应不同，返回此状态码的响应要求请求者重置文档视图。该响应主要是被用于接受用户输入后，立即重置表单，以便用户能够轻松地开始另一次输入。与204响应一样，该响应也被禁止包含任何消息体，且以消息头后的第一个空行结束。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">206<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器已经成功处理了部分 GET 请求。类似于 FlashGet 或者迅雷这类的 HTTP 下载工具都是使用此类响应实现断点续传或者将一个大文档分解为多个下载段同时下载。该请求必须包含 Range 头信息来指示客户端希望得到的内容范围，并且可能包含 If-Range 来作为请求条件。响应必须包含如下的头部域： Content-Range 用以指示本次响应中返回的内容的范围；如果是 Content-Type 为 multipart/byteranges 的多段下载，则每一 multipart 段中都应包含Content-Range 域用以指示本段的内容范围。假如响应中包含 Content-Length，那么它的数值必须匹配它返回的内容范围的真实字节数。Date ETag 和/或 Content-Location，假如同样的请求本应该返回200响应。Expires, Cache-Control，和/或 Vary，假如其值可能与之前相同变量的其他响应对应的值不同的话。假如本响应请求使用了 If-Range 强缓存验证，那么本次响应不应该包含其他实体头；假如本响应的请求使用了 If-Range\n 弱缓存验证，那么本次响应禁止包含其他实体头；这避免了缓存的实体内容和更新了的实体头信息之间的不一致。否则，本响应就应当包含所有本应该返回200响应中应当返回的所有实体头部域。假如 ETag 或 Last-Modified 头部不能精确匹配的话，则客户端缓存应禁止将206响应返回的内容与之前任何缓存过的内容组合在一起。任何不支持 Range 以及 Content-Range 头的缓存都禁止缓存206响应返回的内容。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">207<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">由WebDAV(RFC 2518)扩展的状态码，代表之后的消息体将是一个XML消息，并且可能依照之前子请求数量的不同，包含一系列独立的响应代码。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">300<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">被请求的资源有一系列可供选择的回馈信息，每个都有自己特定的地址和浏览器驱动的商议信息。用户或浏览器能够自行选择一个首选的地址进行重定向。除非这是一个 HEAD 请求，否则该响应应当包括一个资源特性及地址的列表的实体，以便用户或浏览器从中选择最合适的重定向地址。这个实体的格式由 Content-Type&nbsp;\n 定义的格式所决定。浏览器可能根据响应的格式以及浏览器自身能力，自动作出最合适的选择。当然，RFC 2616规范并没有规定这样的自动选择该如何进行。如果服务器本身已经有了首选的回馈选择，那么在 Location 中应当指明这个回馈的 URI；浏览器可能会将这个 Location 值作为自动重定向的地址。此外，除非额外指定，否则这个响应也是可缓存的。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">301<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">被请求的资源已永久移动到新位置，并且将来任何对此资源的引用都应该使用本响应返回的若干个 URI\n 之一。如果可能，拥有链接编辑功能的客户端应当自动把请求的地址修改为从服务器反馈回来的地址。除非额外指定，否则这个响应也是可缓存的。新的永久性的 URI 应当在响应的 Location 域中返回。除非这是一个 HEAD 请求，否则响应的实体中应当包含指向新的 URI 的超链接及简短说明。如果这不是一个 GET 或者 HEAD 请求，因此浏览器禁止自动进行重定向，除非得到用户的确认，因为请求的条件可能因此发生变化。注意：对于某些使用 HTTP/1.0 协议的浏览器，当它们发送的 POST 请求得到了一个301响应的话，接下来的重定向请求将会变成 GET 方式。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">302<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求的资源现在临时从不同的 URI 响应请求。由于这样的重定向是临时的，客户端应当继续向原有地址发送以后的请求。只有在Cache-Control或Expires中进行了指定的情况下，这个响应才是可缓存的。新的临时性的 URI 应当在响应的 Location 域中返回。除非这是一个 HEAD 请求，否则响应的实体中应当包含指向新的 URI 的超链接及简短说明。如果这不是一个 GET 或者 HEAD 请求，那么浏览器禁止自动进行重定向，除非得到用户的确认，因为请求的条件可能因此发生变化。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">303<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">对应当前请求的响应可以在另一个 URI 上被找到，而且客户端应当采用 GET 的方式访问那个资源。这个方法的存在主要是为了允许由脚本激活的POST请求输出重定向到一个新的资源。这个新的 URI&nbsp;\n 不是原始资源的替代引用。同时，303响应禁止被缓存。当然，第二个请求（重定向）可能被缓存。新的 URI 应当在响应的 Location 域中返回。除非这是一个 HEAD 请求，否则响应的实体中应当包含指向新的 URI 的超链接及简短说明。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">304<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">如果客户端发送了一个带条件的 GET 请求且该请求已被允许，而文档的内容（自上次访问以来或者根据请求的条件）并没有改变，则服务器应当返回这个状态码。304响应禁止包含消息体，因此始终以消息头后的第一个空行结尾。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">305<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">被请求的资源必须通过指定的代理才能被访问。Location 域中将给出指定的代理所在的 URI 信息，接收者需要重复发送一个单独的请求，通过这个代理才能访问相应资源。只有原始服务器才能建立305响应。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">306<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">在最新版的规范中，306状态码已经不再被使用。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">307<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求的资源现在临时从不同的URI 响应请求。由于这样的重定向是临时的，客户端应当继续向原有地址发送以后的请求。只有在Cache-Control或Expires中进行了指定的情况下，这个响应才是可缓存的。新的临时性的URI 应当在响应的 Location 域中返回。除非这是一个HEAD 请求，否则响应的实体中应当包含指向新的URI\n 的超链接及简短说明。因为部分浏览器不能识别307响应，因此需要添加上述必要信息以便用户能够理解并向新的 URI 发出访问请求。如果这不是一个GET 或者 HEAD 请求，那么浏览器禁止自动进行重定向，除非得到用户的确认，因为请求的条件可能因此发生变化。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">400<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">1、语义有误，当前请求无法被服务器理解。除非进行修改，否则客户端不应该重复提交这个请求。\n &nbsp; &nbsp; &nbsp; &nbsp;　　2、请求参数有误。<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">401<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">当前请求需要用户验证。该响应必须包含一个适用于被请求资源的 WWW-Authenticate 信息头用以询问用户信息。客户端可以重复提交一个包含恰当的 Authorization 头信息的请求。如果当前请求已经包含了\nAuthorization&nbsp; 证书，那么401响应代表着服务器验证已经拒绝了那些证书。如果401响应包含了与前一个响应相同的身份验证询问，且浏览器已经至少尝试了一次验证，那么浏览器应当向用户展示响应中包含的实体信息，因为这个实体信息中可能包含了相关诊断信息。 &nbsp;&nbsp; <br/></span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">402<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">该状态码是为了将来可能的需求而预留的。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">403<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器已经理解请求，但是拒绝执行它。与401响应不同的是，身份验证并不能提供任何帮助，而且这个请求也不应该被重复提交。如果这不是一个 HEAD&nbsp;\n 请求，而且服务器希望能够讲清楚为何请求不能被执行，那么就应该在实体内描述拒绝的原因。当然服务器也可以返回一个404响应，假如它不希望让客户端获得任何信息。\n &nbsp; &nbsp;<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">404<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求失败，请求所希望得到的资源未被在服务器上发现。没有信息能够告诉用户这个状况到底是暂时的还是永久的。假如服务器知道情况的话，应当使用410状态\n码来告知旧资源因为某些内部的配置机制问题，已经永久的不可用，而且没有任何可以跳转的地址。404这个状态码被广泛应用于当服务器不想揭示到底为何请求\n被拒绝或者没有其他适合的响应可用的情况下。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">405<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求行中指定的请求方法不能被用于请求相应的资源。该响应必须返回一个Allow 头信息用以表示出当前资源能够接受的请求方法的列表。鉴于 PUT，DELETE 方法会对服务器上的资源进行写操作，因而绝大部分的网页服务器都不支持或者在默认配置下不允许上述请求方法，对于此类请求均会返回405错误。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">406<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求的资源的内容特性无法满足请求头中的条件，因而无法生成响应实体。除非这是一个 HEAD 请求，否则该响应就应当返回一个包含可以让用户或者浏览器从中选择最合适的实体特性以及地址列表的实体。实体的格式由 Content-Type&nbsp;\n 头中定义的媒体类型决定。浏览器可以根据格式及自身能力自行作出最佳选择。但是，规范中并没有定义任何作出此类自动选择的标准。\n &nbsp; &nbsp;</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">407<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">与401响应类似，只不过客户端必须在代理服务器上进行身份验证。代理服务器必须返回一个 Proxy-Authenticate 用以进行身份询问。客户端可以返回一个 Proxy-Authorization&nbsp;\n 信息头用以验证。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">408<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求超时。客户端没有在服务器预备等待的时间内完成一个请求的发送。客户端可以随时再次提交这一请求而无需进行任何更改。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">409<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">由于和被请求的资源的当前状态之间存在冲突，请求无法完成。这个代码只允许用在这样的情况下才能被使用：用户被认为能够解决冲突，并且会重新提交新的请求。该响应应当包含足够的信息以便用户发现冲突的源头。冲突通常发生于对 PUT 请求的处理中。例如，在采用版本检查的环境下，某次 PUT\n &nbsp;&nbsp; 提交的对特定资源的修改请求所附带的版本信息与之前的某个（第三方）请求向冲突，那么此时服务器就应该返回一个409错误，告知用户请求无法完成。此时，响应实体中很可能会包含两个冲突版本之间的差异比较，以便用户重新提交归并以后的新版本。<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">410<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">被请求的资源在服务器上已经不再可用，而且没有任何已知的转发地址。这样的状况应当被认为是永久性的。如果可能，拥有链接编辑功能的客户端应当在获得用户\n许可后删除所有指向这个地址的引用。如果服务器不知道或者无法确定这个状况是否是永久的，那么就应该使用404状态码。除非额外说明，否则这个响应是可缓\n存的。410响应的目的主要是帮助网站管理员维护网站，通知用户该资源已经不再可用，并且服务器拥有者希望所有指向这个资源的远端连接也被删除。这类事件在\n限时、增值服务中很普遍。同样，410响应也被用于通知客户端在当前服务器站点上，原本属于某个个人的资源已经不再可用。当然，是否需要把所有永久不可用\n的资源标记为&#39;410&nbsp; Gone&#39;，以及是否需要保持此标记多长时间，完全取决于服务器拥有者。<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">411<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器拒绝在没有定义 Content-Length 头的情况下接受请求。在添加了表明请求消息体长度的有效 Content-Length 头之后，客户端可以再次提交该请求。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">412<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器在验证在请求的头字段中给出先决条件时，没能满足其中的一个或多个。这个状态码允许客户端在获取资源时在请求的元信息（请求头字段数据）中设置先决条件，以此避免该请求方法被应用到其希望的内容以外的资源上。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">413<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器拒绝处理当前请求，因为该请求提交的实体数据大小超过了服务器愿意或者能够处理的范围。此种情况下，服务器可以关闭连接以免客户端继续发送此请求。如果这个状况是临时的，服务器应当返回一个 Retry-After 的响应头，以告知客户端可以在多少时间以后重新尝试。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">414<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求的URI 长度超过了服务器能够解释的长度，因此服务器拒绝对该请求提供服务。这比较少见，通常的情况包括：本应使用POST方法的表单提交变成了GET方法，导致查询字符串（Query String）过长。重定向URI “黑洞”，例如每次重定向把旧的 URI 作为新的 URI 的一部分，导致在若干次重定向后 URI 超长。客户端正在尝试利用某些服务器中存在的安全漏洞攻击服务器。这类服务器使用固定长度的缓冲读取或操作请求的 URI，当 GET后的参数超过某个数值后，可能会产生缓冲区溢出，导致任意代码被执行[1]。没有此类漏洞的服务器，应当返回414状态码。\n &nbsp; &nbsp;<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">415<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">对于当前请求的方法和所请求的资源，请求中提交的实体并不是服务器中所支持的格式，因此请求被拒绝。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">416<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">如果请求中包含了 Range 请求头，并且 Range 中指定的任何数据范围都与当前资源的可用范围不重合，同时请求中又没有定义 If-Range 请求头，那么服务器就应当返回416状态码。假如 Range 使用的是字节范围，那么这种情况就是指请求指定的所有数据范围的首字节位置都超过了当前资源的长度。服务器也应当在返回416状态码的同时，包含一个 Content-Range\n 实体头，用以指明当前资源的长度。这个响应也被禁止使用 multipart/byteranges 作为其 Content-Type。\n &nbsp; &nbsp;<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">417<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">在请求头 Expect 中指定的预期内容无法被服务器满足，或者这个服务器是一个代理服务器，它有明显的证据证明在当前路由的下一个节点上，Expect 的内容无法被满足。<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">421<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">从当前客户端所在的IP地址到服务器的连接数超过了服务器许可的最大范围。通常，这里的IP地址指的是从服务器上看到的客户端地址（比如用户的网关或者代理服务器地址）。在这种情况下，连接数的计算可能涉及到不止一个终端用户。<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">422<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">从当前客户端所在的IP地址到服务器的连接数超过了服务器许可的最大范围。通常，这里的IP地址指的是从服务器上看到的客户端地址（比如用户的网关或者代理服务器地址）。在这种情况下，连接数的计算可能涉及到不止一个终端用户。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">423<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">请求格式正确，但是由于含有语义错误，无法响应。（RFC 4918 WebDAV）423 Locked 当前资源被锁定。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">424<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">由于之前的某个请求发生的错误，导致当前请求失败，例如 PROPPATCH</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">425<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">在WebDav Advanced Collections 草案中定义，但是未出现在《WebDAV 顺序集协议》<br/></span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">426<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">客户端应当切换到TLS/1.0。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">449<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">由微软扩展，代表请求应当在执行完适当的操作后进行重试</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">500<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器遇到了一个未曾预料的状况，导致了它无法完成对请求的处理。一般来说，这个问题都会在服务器的程序码出错时出现。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">501<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器不支持当前请求所需要的某个功能。当服务器无法识别请求的方法，并且无法支持其对任何资源的请求。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">502<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">作为网关或者代理工作的服务器尝试执行请求时，从上游服务器接收到无效的响应。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">503<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">由于临时的服务器维护或者过载，服务器当前无法处理请求。这个状况是临时的，并且将在一段时间以后恢复。如果能够预计延迟时间，那么响应中可以包含一个 Retry-After 头用以标明这个延迟时间。如果没有给出这个\n &nbsp; &nbsp; &nbsp; &nbsp;Retry-After 信息，那么客户端应当以处理500响应的方式处理它。注意：503状态码的存在并不意味着服务器在过载的时候必须使用它。某些服务器只不过是希望拒绝客户端的连接。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">504<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">作为网关或者代理工作的服务器尝试执行请求时，未能及时从上游服务器（URI标识出的服务器，例如HTTP、FTP、LDAP）或者辅助服务器（例如DNS）收到响应。注意：某些代理服务器在DNS查询超时时会返回400或者500错误</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"word-break: break-all; border-color: rgb(255, 255, 255); border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">505<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器不支持，或者拒绝支持在请求中使用的 HTTP 版本。这暗示着服务器不能或不愿使用与客户端相同的版本。响应中应当包含一个描述了为何版本不被支持以及服务器支持哪些协议的实体。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">506<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">由《透明内容协商协议》（RFC 2295）扩展，代表服务器存在内部配置错误：被请求的协商变元资源被配置为在透明内容协商中使用自己，因此在一个协商处理中不是一个合适的重点。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">507<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器无法存储完成请求所必须的内容。这个状况被认为是临时的。</span></p></td></tr><tr class=\"ue-table-interlace-color-double\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">509<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">服务器达到带宽限制。这不是一个官方的状态码，但是仍被广泛使用。</span></p></td></tr><tr class=\"ue-table-interlace-color-single\"><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"middle\" width=\"59\" align=\"center\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">510<br/></span></p></td><td style=\"border-color: rgb(255, 255, 255); word-break: break-all; border-width: 1px; border-style: solid;\" valign=\"top\" width=\"1045\"><p style=\"line-height: 1.5em; margin-bottom: 10px; margin-top: 10px;\"><span style=\"font-size: 12px;\">获取资源所需要的策略并没有没满足。<br/></span></p></td></tr></tbody></table>','2015-09-17 14:57:35','2015-09-17 14:57:35','55ffa1ba9ff1e8de3e6cc348','1','HTTP状态码（HTTP Status Code）用来表示web服务器响应客户端的HTTP状态。',1,NULL,1),('55ffa7ace004e8de780b6800','图标——Icon glyphs','','2015-09-21 14:46:04','2015-09-21 14:46:04','55ffa1ba9ff1e8de3e6cc348','1','Glyphicons 是在 Web 项目中使用的图标字体。',1,'/online/iconGlyphs',2),('5600e85f4f88f20c9220e95f','三年程序员的实战开发经验之谈 — 做人做事','<p style=\"text-align: left; text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\"><strong><span style=\"color: rgb(0, 176, 80);\">以下文章摘自网络 </span></strong><strong><span style=\"color: rgb(0, 176, 80);\"></span></strong><strong><span style=\"color: rgb(0, 176, 80);\"><a style=\"color: rgb(0, 176, 80); text-decoration: underline;\" _src=\"http://blog.csdn.net/xiaohai798/article/details/47623011\" href=\"http://blog.csdn.net/xiaohai798/article/details/47623011\"><span style=\"color: rgb(0, 176, 80);\">http://blog.csdn.net/xiaohai798/article/details/47623011</span></a><span style=\"color: rgb(0, 176, 80);\">&nbsp; </span><br/></span></strong></span></p><p style=\"text-indent: 0em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><br/></span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">近来工作不在状态，烦躁，没事就写写鸡汤 扯扯淡吧。我知道其实还是很多人喜欢看扯淡的。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">毕业三年多，真正工作也快三年了。工作前大概4个月时间，在一家公司自学过java se 、java ee整个体系内容以及oracle \nmysql数据基础。&nbsp;第一年做过小项目单独模块的需求分析、设计、编码、测试、部署、上线，包括前台客户端的html、css、js这些技术，也包括前台服务端的java \nee 体系技术（jsp servlet ssh等），还包括后台的数据库简单的表设计、sql语句、简单的触发器、procedure 这些技术。<span style=\"font-size: 14px; color: rgb(0, 0, 0);\"><span style=\"font-size: 14px;\">第一年干的事情虽然比较杂点，但是让我更加具体的学习了一般java \nee项目的整个开发技术及流程，更重要的是用几个小项目印证了之前学的内容，使自己对java \nee的理解更深</span>。</span>第二年到今年5月份，主要是在一个电信行业的运营数据存储项目做etl和数据库开发及web服务接口的开发，期间学习到了数仓类项目的系统架构、数据架构，系统建设，电信o域的业务，对oracle数据库、索引有了更深的理解，学习到了pl \nsql编程技术，学习到了oracle数据库 大数据量的数据处理技术细节。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">总结了一些项目工作中的经验。（仅是行业软件项目开发经验）</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(255, 0, 0);\">做事建议</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">1 、项目事情任务很多时，一件件的解决</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;说的是当你因为项目任务多的感觉按时完不成感到烦躁一件也不想做的时候，或者是因为一件比较难的你觉得完成不了导致其他事情也不想做的时候。就记住这句话，如果是第一个原因，你就别想那么多，不管事情多不多，一件件的来做一件是一件，如果你什么都不做停在那里的话不但没有进度，可能还会造成恶性循环。第二个原因的话就跳过难的地方，做能做的，不然因为一件事没有进度也说不过去，客户、领导都没法交代。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">2 、\n任务有计划 到周到日 工作松紧有度</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">不至于加班 也不至于太闲 工作的效率 即真正工作的有效时间要提高。不要拖延任务 不然容易形成恶性循环 \n排计划的目的是战胜惰性，充分利用白天的工作时间。心里面知道每天当天做哪些事情，并把它做完，不至于看看微信 聊聊天 \n一天的时间就那样过了。<strong>你所拥有的最重要的东西就是你的时间，因为你不能创造更多时间。</strong></span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">3 、随时记 随地记 及时记</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;生活里的想法、点子&nbsp; 稍纵即逝 所以为避免忘记 \n随时记录到手机。不要小看这个东西，以后可能会给你大作用。还有就是平常你花了很长时间解决了一个难题或者错误的时候，<span style=\"font-size: 14px; color: rgb(0, 0, 0);\"><span style=\"font-size: 14px;\"><strong>一定记住一定要把它记下来，不论当时有多忙，哪怕记几个关键字都行</strong></span>。</span>因为一是这是你的劳动成果二是你知道下次会不会还会碰到这个问题，所以备忘，下次就不用做重复的工作了。及时记：还有开完一些会议比如需求对接会后 \n，应该立即会后就把它整理记下来，不要想着明天再搞，因为你明天说不定就忘了哪点了。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">4 、困难时&nbsp; 坚持不懈 不放弃</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">首先，正视困难，不要觉得一有困难就很烦，就做不下去了，你要在心里面对自己说 \n，<span style=\"font-size: 14px; color: rgb(0, 176, 80);\"><strong>如果你做的事情毫不费力，那就是在浪费时间。所以想想解决难题后，那个难题也不算什么了，迎难而上，加油。</strong></span></span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">5 、整体进度把控</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">&nbsp;说的是 ，如果你负责的是一个项目或者一个项目的其中一个模块，不要让困难的事或者其他不利因素 \n耽误你的整体进度。又比如你刚进一个公司负责一块东西，更开始有个人带着你，但是注意千万别太依赖这个人，因为 人有惰性 无论是 水平高 \n或者低，资历是老或者不老，假如这模块有个难题，他可以拖着不搞，但是你不行因为你是负责人。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">6 、其他厂家的需求对接会注意事项</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">把这个单独拿出来 讲是因为 仓库系统 经常要和局方以及其他厂家的boss系统人调接口，开需求对接会。这个东西处理不好的话，可能会给你挖个坑出来。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">一、一般若是某个涉及到多个系统 厂家的接口有问题的话，大家一起开会的时候 \n每个系统基本都是会说不是自己的问题，把问题抛给别人。这个时候你要之前要先查清楚是不是自己系统的问题，如果确认不是自己的问题，会上在局方 \n各系统人都在的时候一定要说出来，不要等到会下再说，不然到时候几个系统一起查问题，还是会把你拽着，烦不说（不知道会遇上什么样的奇葩局方 和其他系统的人） \n还耽误你正常工作的时间</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">二、新需求的时候，举个例子 ，某个比较难做的东西可能在你这边能实现，在其他系统也能实现，但是大家都不想做，这个时候你就要先声夺人 ，抢先说 \n在你这边做的风险 延迟什么的或者有其他很多事情要忙什么的。你不说可能就默认抛给你。总之，态度不能软也不能太强硬，有个度。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(255, 0, 0);\">做人建议</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">7 、同事关系</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">跟同事关系搞好，自然不用说了，比如遇到问题的时候 互相帮助，有时候帮助别人干事 解决问题 \n是再帮自己铺路，有可能明天你自己就会遇到相同的问题。要注意，乐于帮助同事是好的 ，但是不要太过友好，工作易被打断，&nbsp;尤其有些程序猿喜欢上来就问 会养成坏习惯 \n同时不利自己工作。这个时候，拒绝的话你就要注意说话了，可以说事情忙待会帮他等理由，但是不要直接拒绝。总之，真心待人，但不要委屈自己即可。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">8 、领导 客户关系</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">就我自己接触的程序员而言，大多是比较内向 \n不怎么说话的，所以平常一般跟领导的沟通都是比较少的。这样的话是不利于在公司长期发展的，最基本的，平常偶然碰见领导有些程序可能就低头过去了，最好别这样，起码可以打个招呼。一起坐电梯或者下班的时候 \n可以聊聊生活上的事什么的。或者吃饭的时候碰到，你要喝的可以顺便给同事及领导叫一份。这些看起来很小、琐碎的事情，都可能让领导对你加深映像，就这么点印象可能让你在同等条件下就比别人多了个机会。这个其实就是人之常情没什么，其实就跟自己遇到什么事情会先想到自己的家人 \n亲戚 朋友一样。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">说说 现在社会的首因 和近因效应严重，人们往往会根据第一次的映像去判断一个人，所以去一家新单位的时候，最开始的一段时间 \n尽量表现的好点，因为领导和客户对你的第一映像很重要，第一映像好，你以后在公司的发展 和在客户的工作都会好做。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px; color: rgb(0, 176, 240);\">9 、倾向于做领导 组织者</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">这个当然是要看个人的发展方向了，如果就是一直想深钻技术，那就不必看这个了。说这个其实是很多程序员现在基本天天就在闷头干活，回家就宅在家里。如果想以后生活的更好或者实现财务自由，肯定要注意这个，比如临时来了个大功能模块需求需要人做，而你又正好闲时，可以做下，不要觉得自己多干活了什么的，而且你可以要人。还有就是平时项目组搞个活动 \n没人组织的话，你也可以主动点申请来搞。总而言之，积极点没坏处。</span></p><p style=\"text-indent: 2em; line-height: 1.75em;\"><span style=\"font-size: 14px;\">最后，说了那么多鸡汤再好，也要实际去行动。</span></p><p><br/></p>','2015-09-22 13:34:23','2015-09-22 13:34:23','2','1','近来工作不在状态，烦躁，没事就写写鸡汤 扯扯淡吧。我知道其实还是很多人喜欢看扯淡的。',1,'',1),('56021a1c9293f20cb3dac11a','CSS3 calc() 会计算的属性','<p style=\"line-height: normal;\"><span style=\"font-size: 14px;\"><br/></span></p><p style=\"line-height: normal;\"><span style=\"font-size: 14px;\">calc是英文单词calculate(计算)的缩写，是css3的一个新增的功能，你可以使用calc()给元素的border、margin、pading、font-size和width等属性设置动态值。<br/></span></p><p style=\"line-height: normal;\"><span style=\"font-size: 14px;\">以前我们可以使用box-sizing:border-box;来设置盒子的属性为不加上边距。现在我们又多了一个选择了。但要注意，两者只能使用一个哦，否则就会造成冲突了。<br/></span></p><p style=\"line-height: normal;\"><span style=\"font-size: 14px;\">怎么使用？</span></p><p style=\"line-height: normal;\"><span style=\"font-size: 14px;\">calc()可以使用数学运算中的简单加（+）、减（-）、乘（*）和除（/）来解决问题，而且还可以根据单位如px,em,rem和百分比来转化计算。</span></p><p style=\"line-height: normal;\"><span style=\"font-size: 14px;\">比如三局平均分布的布局，中间间距为5像素。</span></p><p><br/></p><p><span style=\"font-size: 14px;\">做成如下效果，每行3个对象 ： 拖动浏览器大小，内容自动按比例缩放。<br/></span></p><p><img style=\"width: 650px; height: 250px;\" src=\"/resources/attached/image/201509231442977648284074382.jpg\" title=\"201509231442977852829078442.jpg\" alt=\"201509231442977852829078442.jpg\" height=\"250\" border=\"0\" vspace=\"0\" width=\"650\"/></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;style type=&quot;text/css&quot;&gt;<br/> &nbsp; &nbsp;*{margin: 0; padding: 0;}<br/> &nbsp; &nbsp;.col-3{width: calc(100%/3 - 5px); float: left; margin-right: calc(5px*3 /2); background: #eee; color: #333; height: 100px; text-align: center; margin-bottom: calc(5px*3 /2); font-size: 18px; line-height: 100px;}<br/> &nbsp; &nbsp;.col-3:nth-child(3){margin-right: 0;}<br/>&lt;/style&gt;<br/></span></code></pre><p><br/></p><p><a style=\"text-decoration: underline; color: rgb(0, 176, 80); font-size: 14px;\" title=\"演示\" target=\"_blank\" href=\"http://caibaojian.com/demo/2014/12/calc.html\"><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">在线演示</span></a></p><p><br/></p><p><br/></p>','2015-09-23 11:18:52','2015-09-23 11:18:52','5','1','calc是css3的一个新增的功能，你可以使用calc()给元素的border、margin、pading、font-size和width等属性设置动态值。',1,'',1),('56023001937bf20c9ffdec13','kill -9杀掉nginx主进程、reload失败解决办法','<p><span style=\"font-size: 14px;\"><br/></span></p><p><span style=\"font-size: 14px;\">前言：</span></p><p><span style=\"font-size: 14px;\">无意间使用 kill -9 命令杀掉了nginx的主进程，当我再次使用 ./nginx -s reload 重新刷新nginx的时候，一直出现了下面的错误信息：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">nginx:&nbsp;[alert]&nbsp;kill(27905,&nbsp;1)&nbsp;failed&nbsp;(3:&nbsp;No&nbsp;such&nbsp;process)<br/></span></code></pre><p><span style=\"font-size: 14px;\">同时，执行命令 ./nginx -t 返回的结果如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">nginx:&nbsp;the&nbsp;configuration&nbsp;file&nbsp;/opt/nginx-1.4.7/conf/nginx.conf&nbsp;syntax&nbsp;is&nbsp;ok<br/>nginx:&nbsp;configuration&nbsp;file&nbsp;/opt/nginx-1.4.7/conf/nginx.conf&nbsp;test&nbsp;is&nbsp;successful<br/></span></code></pre><p><br/></p><p><span style=\"font-size: 14px;\">nginx正常运行，只是无法使用reload刷新，我也头大了，怎么办呢。</span></p><p><span style=\"font-size: 14px;\">网上找到如下解决方法：</span></p><p><span style=\"font-size: 14px;\">文章地址： </span><a style=\"text-decoration: underline; font-size: 14px;\" _src=\"http://www.2cto.com/os/201303/198394.html\" href=\"http://www.2cto.com/os/201303/198394.html\"><span style=\"font-size: 14px;\">http://www.2cto.com/os/201303/198394.html</span></a><br/></p><p><br/></p><p><span style=\"font-size: 14px;\">文章中有一个命令 fuser -n tcp 80&nbsp; 查看80端口被哪些程序占用。最终控制台输出的信息如下：<br/></span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">80/tcp: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4613 &nbsp;4614<br/></span></code></pre><p></p><p><span style=\"font-size: 14px;\">好吧，kill掉这2个子进程。</span></p><p><span style=\"font-size: 14px;\">重新启动nginx，再次使用 ./nginx -s reload ，，OK了！</span><img src=\"http://img.baidu.com/hi/jx2/j_0069.gif\"/></p><p><br/></p><p><span style=\"font-size: 14px;\">还好没有酿成大祸。。记录下来，以便需要时参考。<img src=\"http://img.baidu.com/hi/jx2/j_0056.gif\"/><br/></span></p><p><span style=\"font-size: 14px;\"><br/></span></p><p><span style=\"font-size: 14px;\"></span></p>','2015-09-23 12:52:17','2015-09-23 12:52:17','55dbcbe592eaf20c53d24e8b','1','kill -9杀掉nginx主进程，使用./nginx -s reload出现 nginx: [alert] kill(27905, 1) failed (3: No such process)失败信息的解决办法。',1,'',1),('56023914937bf20ca0fdec13','nginx开启GZIP来压缩网页','<p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\">HTTP协议上的GZIP编码是一种用来改进web应\n用程序性能的技术。大流量的WEB站点常常使用GZIP压缩技术来让用户感受更快的速度。这一般是指WWW服务器中安装的一个功能，当有人来访问这个服务\n器中的网站时，服务器中的这个功能就将网页内容压缩后传输到来访的电脑浏览器中显示出来.一般对纯文本内容可压缩到原大小的40%.这样传输就快了，效果\n就是你点击网址后会很快的显示出来.当然这也会增加服务器的负载. 一般服务器中都安装有这个功能模块的。</span></p><p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\">减少文件大小有两个明显的好处，一是可以减少存储空间，二是通过网络传输文件时，可以减少传输的时间。gzip 是在 Linux 系统中经常使用的一个对文件进行压缩和解压缩的命令，既方便又好用。</span></p><p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\">在Nginx安装完成之后，我们可以开启Gzip压缩功能，这里<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">Nginx默认只能对text/</span><a style=\"color: rgb(0, 176, 80); text-decoration: underline;\" href=\"http://caibaojian.com/t/html\" title=\"html\"><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">html</span></a><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">类型的文件进行压缩</span>。</span></p><p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\">下面的指令为开启Gzip的指令：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;启用&nbsp;gzip&nbsp;压缩功能<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip&nbsp;&nbsp;on;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;默认值是1.1，就是说对HTTP/1.1协议的请求才会进行gzip压缩<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_http_version&nbsp;1.1;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_vary&nbsp;on;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;压缩级别，1压缩比最小处理速度最快，9压缩比最大但处理最慢，同时也最消耗CPU,一般设置为3就可以了<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_comp_level&nbsp;6;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;nginx&nbsp;做前端代理时启用该选项，表示无论后端服务器的headers头返回什么信息，都无条件启用压缩<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_proxied&nbsp;any;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;什么类型的页面或文档启用压缩<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_types&nbsp;text/plain&nbsp;text/css&nbsp;application/json&nbsp;application/x-javascript&nbsp;text/xml&nbsp;application/xml&nbsp;application/xml+rss&nbsp;text/javascript&nbsp;image/jpeg&nbsp;image/gif&nbsp;image/png;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;最小压缩的页面，如果页面过于小，可能会越压越大，这里规定大于1K的页面才启用压缩<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_min_length&nbsp;&nbsp;1024;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_buffers&nbsp;16&nbsp;8k;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;禁用IE6的gzip压缩<br/>&nbsp;&nbsp;&nbsp;&nbsp;gzip_disable &quot;MSIE&nbsp;[1-6].(?!.*SV1)&quot;;<br/></span></code></pre><p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\"><br/></span></p><p><span style=\"font-size: 14px;\">相关配置说明：</span></p><p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\">1、在<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">gzip_http_version的默认值是1.1</span>，就是说对HTTP/1.1协议的请求才会进行gzip压缩。</span></p><p><span style=\"font-size: 14px;\">如果使用了proxy_pass进行反向代理，那么nginx和后端的upstream server之间是用HTTP/1.0协议通信的，如果使用nginx通过反向代理做Cache Server，前端的nginx没有开启gzip，且后端的nginx上未设置gzip_http_version为1.0，那么Cache的url将不会被gzip压缩。</span></p><p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\">2、<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">gzip_disable的设置是禁用IE6的gzip压缩</span></span></p><p><span style=\"font-size: 14px;\">IE6的某些版本对gzip的压缩支持不是很好，会造成页面的假死。对img进行gzip后会造成IE6的假死，把对img的gzip压缩去掉后就正常了。为了确保其它的IE6版本不出问题，所以加上了gzip_disable配置项。</span></p><p style=\"text-indent: 2em;\"><span style=\"font-size: 14px;\">3、<span style=\"font-size: 14px; color: rgb(0, 176, 80);\">gzip_min_length设置允许压缩的页面最小字节数</span>，页面字节数从header头中的Content-Length中进行获取。</span></p><p><span style=\"font-size: 14px;\">默认值是0，不管页面多大都压缩。建议设置成大于1k的字节数，小于1k可能会越压越大。 即: gzip_min_length 1024。</span></p><p><span style=\"font-size: 14px;\"><br/></span></p>','2015-09-23 13:31:01','2015-09-23 13:31:01','55dbcbe592eaf20c53d24e8b','1','HTTP协议上的GZIP编码是一种用来改进web应用程序性能的技术。大流量的WEB站点常常使用GZIP压缩技术来让用户感受更快的速度。',1,'',1),('56175b9af45af20cfb95b43a','只让输入数字、字母、中文的输入框','<p><br/></p><p><span style=\"font-size: 14px;\">输入框只能输入字母和下横线的正则表达式</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;input type=&quot;text&quot; onkeyup=&quot;this.value=this.value.replace(/[^_a-zA-Z]/g,&#39;&#39;)&quot; onpaste=&quot;this.value=this.value.replace(/[^_a-zA-Z]/g,&#39;&#39;)&quot;&gt;<br/></span></code></pre><p></p><p><br/></p><p><span style=\"font-size: 14px;\">只能输入数字和英文</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;input type=&quot;text&quot; onkeyup=&quot;this.value=this.value.replace(/[\\W]/g,&#39;&#39;)&quot; onpaste=&quot;this.value=this.value.replace(/[\\W]/g,&#39;&#39;)&quot;&gt;<br/></span></code></pre><p><br/></p><p><span style=\"font-size: 14px;\">输入框只能输入字母数字和下横线的正则表达式</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;input type=&quot;text&quot; onkeyup=&quot;this.value=this.value.replace(/[^\\w]/g,&#39;&#39;)&quot; onpaste=&quot;this.value=this.value.replace(/[^\\w]/g,&#39;&#39;)&quot;&gt;<br/></span></code></pre><p></p><p><span style=\"font-size: 14px;\">或</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;input type=&quot;text&quot; onkeyup=&quot;this.value=this.value.replace(/[\\W]/g,&#39;&#39;)&quot; onpaste=&quot;this.value=this.value.replace(/[\\W]/g,&#39;&#39;)&quot;&gt;<br/></span></code></pre><p><br/></p><p><span style=\"font-size: 14px;\">只能输入中文</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;input type=&quot;text&quot; onkeyup=&quot;this.value=this.value.replace(/[^\\u4E00-\\u9FA5]/g,&#39;&#39;)&quot; onafterpaste=&quot;this.value=this.value.replace(/[^\\u4E00-\\u9FA5]/g,&#39;&#39;)&quot; /&gt;<br/></span></code></pre><p><br/></p><p><span style=\"font-size: 14px;\">只能输入全角字符</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;input type=&quot;text&quot; onkeyup=&quot;this.value=this.value.replace(/[^\\uFF00-\\uFFFF]/g,&#39;&#39;)&quot; onafterpaste=&quot;this.value=this.value.replace(/[^\\uFF00-\\uFFFF]/g,&#39;&#39;)&quot; /&gt;<br/></span></code></pre><p></p><p><br/></p>','2015-10-09 14:15:54','2015-10-09 14:15:54','5','1','只让输入数字、字母、中文的输入框，通过dom标签的属性来控制，无需通过js进行校验。',1,'',1),('5618d7cb16eff20ca24693c2','js调用高德API获取所在当前城市','<p><br/></p><p><span style=\"font-size: 14px;\">可以在js代码中直接调用API接口，获取所处当前城市信息，代码如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">&lt;script type=&quot;text/javascript&quot;&gt;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;function getCurrentCity(){<br/> &nbsp; &nbsp; &nbsp; &nbsp;$.ajax({<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type: &quot;get&quot;,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url: &quot;http://webapi.amap.com/maps/ipLocation?key=608d75903d29ad471362f8c58c550daf&quot;,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dataType: &#39;text&#39;,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;success: function(data) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//转换为JSON对象<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var jsonObj = eval(&quot;(&quot; + data.replace(&#39;(&#39;,&#39;&#39;).replace(&#39;)&#39;,&#39;&#39;).replace(&#39;;&#39;,&#39;&#39;) + &quot;)&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//当前城市<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;#cityName&quot;).html(jsonObj.city);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;});<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;//页面加载获取当前所在城市信息<br/> &nbsp; &nbsp;$(document).ready(function(){<br/> &nbsp; &nbsp; &nbsp; &nbsp;getCurrentCity();<br/> &nbsp; &nbsp;});<br/>&lt;/script&gt;<br/></span></code></pre><p><br/></p><p><br/></p>','2015-10-10 17:18:02','2015-10-10 17:18:02','5','1','js调用高德API获取所在当前城市，返回json结果，解析出城市名称、代码、经纬度信息。',1,'',1),('561b256116eff20ca34693c2','jquery仿ios日期时间插件','<p><br/></p><p><span style=\"font-size: 14px;\">Demo下载：<br/></span></p><p style=\"line-height: 16px;\"><img style=\"vertical-align: middle; margin-right: 2px;\" src=\"http://www.2b2b92b.com/resources/ueditor/dialogs/attachment/fileTypeImages/icon_rar.gif\"/><a style=\"color: rgb(0, 102, 204); font-size: 14px; text-decoration: underline;\" href=\"/resources/attached/file/手机时间控件.zip\" title=\"手机时间控件.zip\"><span style=\"font-size: 14px;\">手机时间控件.zip</span></a></p><p><br/></p><p><br/></p><p><span style=\"font-size: 14px;\">使用之前，请在页面中加入以下js和css：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">jquery-1.9.1.js<br/>mobiscroll.core-2.5.2.js<br/>mobiscroll.core-2.5.2-zh.js<br/>mobiscroll.core-2.5.2.css<br/>mobiscroll.animation-2.5.2.css<br/>mobiscroll.datetime-2.5.1.js<br/>mobiscroll.datetime-2.5.1-zh.js<br/>mobiscroll.android-ics-2.5.2.js<br/>mobiscroll.android-ics-2.5.2.css<br/></span></code></pre><p><br/></p><p><br/></p><p><span style=\"font-size: 14px;\">插件效果如下（主题样式、显示方式、日期时间可以自己通过配置选择）：<br/></span></p><p><br/></p><p><span style=\"font-size: 14px;\">日期：</span></p><p><img src=\"http://www.2b2b92b.com/resources/attached/image/201510121444618876790028162.jpg\"/><br/></p><p><br/></p><p><span style=\"font-size: 14px;\">日期时间：</span></p><p><img src=\"http://www.2b2b92b.com/resources/attached/image/201510121444619243102031919.jpg\"/></p><p><br/></p><p><span style=\"font-size: 14px;\">时间：</span></p><p><img src=\"http://www.2b2b92b.com/resources/attached/image/201510121444619406588091070.jpg\"/><br/></p><p><br/></p><p></p>','2015-10-12 11:13:37','2015-10-12 11:13:37','5','1','jquery仿ios日期时间插件。可配置。',1,'',1),('561b6f0716eff20ca44693c2','JS身份证真实性校验（一）','<p><br/></p><p><span style=\"font-size: 14px; color: rgb(0, 176, 80);\">JS——身份证真实性校验，可直接复制使用，支持15、18位校验，代码如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 14px;\">//这个可以验证15位和18位的身份证，并且包含生日和校验位的验证。 &nbsp;<br/>//如果有兴趣，还可以加上身份证所在地的验证，就是前6位有些数字合法有些数字不合法。 &nbsp;<br/>function isIdCardNo(num) {<br/> &nbsp; &nbsp;num = num.toUpperCase();<br/> &nbsp; &nbsp;//身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp;if (!(/(^\\d{15}$)|(^\\d{17}([0-9]|X)$)/.test(num))) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;alert(&#39;输入的身份证号长度不对，或者号码不符合规定！\\n15位号码应全为数字，18位号码末位可以为数字或X。&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 <br/> &nbsp; &nbsp;//下面分别分析出生日期和校验位 <br/> &nbsp; &nbsp;var len, re;<br/> &nbsp; &nbsp;len = num.length;<br/> &nbsp; &nbsp;if (len == 15) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;re = new RegExp(/^(\\d{6})(\\d{2})(\\d{2})(\\d{2})(\\d{3})$/);<br/> &nbsp; &nbsp; &nbsp; &nbsp;var arrSplit = num.match(re);<br/> &nbsp; &nbsp; &nbsp; &nbsp;//检查生日日期是否正确<br/> &nbsp; &nbsp; &nbsp; &nbsp;var dtmBirth = new Date(&#39;19&#39; + arrSplit[2] + &#39;/&#39; + arrSplit[3] + &#39;/&#39; + arrSplit[4]);<br/> &nbsp; &nbsp; &nbsp; &nbsp;var bGoodDay;<br/> &nbsp; &nbsp; &nbsp; &nbsp;bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;&amp; ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;&amp; (dtmBirth.getDate() == Number(arrSplit[4]));<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!bGoodDay) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(&#39;输入的身份证号里出生日期不对！&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//将15位身份证转成18位 <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var arrCh = new Array(&#39;1&#39;, &#39;0&#39;, &#39;X&#39;, &#39;9&#39;, &#39;8&#39;, &#39;7&#39;, &#39;6&#39;, &#39;5&#39;, &#39;4&#39;, &#39;3&#39;, &#39;2&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var nTemp = 0, i;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num = num.substr(0, 6) + &#39;19&#39; + num.substr(6, num.length - 6);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (i = 0; i &lt; 17; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nTemp += num.substr(i, 1) * arrInt[i];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num += arrCh[nTemp % 11];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return num;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;if (len == 18) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;re = new RegExp(/^(\\d{6})(\\d{4})(\\d{2})(\\d{2})(\\d{3})([0-9]|X)$/);<br/> &nbsp; &nbsp; &nbsp; &nbsp;var arrSplit = num.match(re);<br/> &nbsp; &nbsp; &nbsp; &nbsp;//检查生日日期是否正确 <br/> &nbsp; &nbsp; &nbsp; &nbsp;var dtmBirth = new Date(arrSplit[2] + &quot;/&quot; + arrSplit[3] + &quot;/&quot; + arrSplit[4]);<br/> &nbsp; &nbsp; &nbsp; &nbsp;var bGoodDay;<br/> &nbsp; &nbsp; &nbsp; &nbsp;bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;&amp; ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;&amp; (dtmBirth.getDate() == Number(arrSplit[4]));<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!bGoodDay) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(dtmBirth.getYear());<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(arrSplit[2]);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(&#39;输入的身份证号里出生日期不对！&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//检验18位身份证的校验码是否正确。 <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var valnum;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var arrCh = new Array(&#39;1&#39;, &#39;0&#39;, &#39;X&#39;, &#39;9&#39;, &#39;8&#39;, &#39;7&#39;, &#39;6&#39;, &#39;5&#39;, &#39;4&#39;, &#39;3&#39;, &#39;2&#39;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var nTemp = 0, i;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (i = 0; i &lt; 17; i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nTemp += num.substr(i, 1) * arrInt[i];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;valnum = arrCh[nTemp % 11];<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (valnum != num.substr(17, 1)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(&#39;18位身份证的校验码不正确！应该为：&#39; + valnum);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return num;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;return false;<br/>}<br/></span></code></pre><p></p><p><br/></p>','2015-10-12 16:27:52','2015-10-12 16:27:52','5','1','JS身份证真实性校验，第一种实现方法。',1,'',1),('561b71e216eff20ca54693c2','JS身份证真实性校验（二）','<pre class=\"brush:java;toolbar:false\"><code>var&nbsp;Wi&nbsp;=&nbsp;[&nbsp;7,&nbsp;9,&nbsp;10,&nbsp;5,&nbsp;8,&nbsp;4,&nbsp;2,&nbsp;1,&nbsp;6,&nbsp;3,&nbsp;7,&nbsp;9,&nbsp;10,&nbsp;5,&nbsp;8,&nbsp;4,&nbsp;2,&nbsp;1&nbsp;];&nbsp;//&nbsp;加权因子\nvar&nbsp;ValideCode&nbsp;=&nbsp;[&nbsp;1,&nbsp;0,&nbsp;10,&nbsp;9,&nbsp;8,&nbsp;7,&nbsp;6,&nbsp;5,&nbsp;4,&nbsp;3,&nbsp;2&nbsp;];&nbsp;//&nbsp;身份证验证位值.10代表X\n\nfunction&nbsp;idCardInValid(idCard)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;idCard&nbsp;=&nbsp;trim(idCard.replace(/&nbsp;/g,&nbsp;&quot;&quot;));&nbsp;//&nbsp;去掉字符串头尾空格\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(idCard.length&nbsp;==&nbsp;15)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;isValidityBrithBy15IdCard(idCard);&nbsp;//&nbsp;进行15位身份证的验证\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;if&nbsp;(idCard.length&nbsp;==&nbsp;18)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;a_idCard&nbsp;=&nbsp;idCard.split(&quot;&quot;);&nbsp;//&nbsp;得到身份证数组\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(isValidityBrithBy18IdCard(idCard)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&amp;&nbsp;isTrueValidateCodeBy18IdCard(a_idCard))&nbsp;{&nbsp;//&nbsp;进行18位身份证的基本验证和第18位的验证\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\n/**\n&nbsp;*&nbsp;判断身份证号码为18位时最后的验证位是否正确\n&nbsp;*&nbsp;\n&nbsp;*&nbsp;@param&nbsp;a_idCard\n&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;身份证号码数组\n&nbsp;*&nbsp;@return\n&nbsp;*/\nfunction&nbsp;isTrueValidateCodeBy18IdCard(a_idCard)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;sum&nbsp;=&nbsp;0;&nbsp;//&nbsp;声明加权求和变量\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(a_idCard[17].toLowerCase()&nbsp;==&nbsp;&#39;x&#39;)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a_idCard[17]&nbsp;=&nbsp;10;&nbsp;//&nbsp;将最后位为x的验证码替换为10方便后续操作\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;17;&nbsp;i++)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum&nbsp;+=&nbsp;Wi[i]&nbsp;*&nbsp;a_idCard[i];&nbsp;//&nbsp;加权求和\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;valCodePosition&nbsp;=&nbsp;sum&nbsp;%&nbsp;11;&nbsp;//&nbsp;得到验证码所位置\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(a_idCard[17]&nbsp;==&nbsp;ValideCode[valCodePosition])&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\n/**\n&nbsp;*&nbsp;验证18位数身份证号码中的生日是否是有效生日\n&nbsp;*&nbsp;\n&nbsp;*&nbsp;@param&nbsp;idCard\n&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;18位书身份证字符串\n&nbsp;*&nbsp;@return\n&nbsp;*/\nfunction&nbsp;isValidityBrithBy18IdCard(idCard18)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;year&nbsp;=&nbsp;idCard18.substring(6,&nbsp;10);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;month&nbsp;=&nbsp;idCard18.substring(10,&nbsp;12);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;day&nbsp;=&nbsp;idCard18.substring(12,&nbsp;14);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;temp_date&nbsp;=&nbsp;new&nbsp;Date(year,&nbsp;parseFloat(month)&nbsp;-&nbsp;1,&nbsp;parseFloat(day));\n&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;这里用getFullYear()获取年份，避免千年虫问题\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(temp_date.getFullYear()&nbsp;!=&nbsp;parseFloat(year)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;temp_date.getMonth()&nbsp;!=&nbsp;parseFloat(month)&nbsp;-&nbsp;1\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;temp_date.getDate()&nbsp;!=&nbsp;parseFloat(day))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\n/**\n&nbsp;*&nbsp;验证15位数身份证号码中的生日是否是有效生日\n&nbsp;*&nbsp;\n&nbsp;*&nbsp;@param&nbsp;idCard15\n&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15位书身份证字符串\n&nbsp;*&nbsp;@return\n&nbsp;*/\nfunction&nbsp;isValidityBrithBy15IdCard(idCard15)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;year&nbsp;=&nbsp;idCard15.substring(6,&nbsp;8);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;month&nbsp;=&nbsp;idCard15.substring(8,&nbsp;10);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;day&nbsp;=&nbsp;idCard15.substring(10,&nbsp;12);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;temp_date&nbsp;=&nbsp;new&nbsp;Date(year,&nbsp;parseFloat(month)&nbsp;-&nbsp;1,&nbsp;parseFloat(day));\n&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(temp_date.getYear()&nbsp;!=&nbsp;parseFloat(year)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;temp_date.getMonth()&nbsp;!=&nbsp;parseFloat(month)&nbsp;-&nbsp;1\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;temp_date.getDate()&nbsp;!=&nbsp;parseFloat(day))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\n//&nbsp;去掉字符串头尾空格\nfunction&nbsp;trim(str)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;str.replace(/(^\\s*)|(\\s*$)/g,&nbsp;&quot;&quot;);\n}</code></pre><p><span style=\"font-size: 14px;\"></span><br/></p>','2015-10-12 16:40:02','2015-10-12 16:40:02','5','1','JS身份证真实性校验，第二种实现方式。',1,'',1),('561b757d16eff20ca64693c2','jquery点击图片选中特效','','2015-10-12 16:55:26','2015-10-12 16:55:26','5','1','jquery点击图片选中特效。',1,'/resources/demoSources/jquery_imgclick/index.html',2),('562dd9142b1ff20ca07f25e7','Java中的24种设计模式与7大原则','<p style=\"line-height: 2em;\"><span style=\"font-size: 14px; color: rgb(255, 0, 0);\">一、创建型模式</span><span style=\"font-size: 14px;\"></span></p><p style=\"line-height: 2em;\"><span style=\"font-size: 14px;\">1、抽象工厂模式(Abstract factory pattern): 提供一个接口, 用于创建相关或依赖对象的家族, 而不需要指定具体类.<br/>2、生成器模式(Builder pattern): 使用生成器模式封装一个产品的构造过程, 并允许按步骤构造. 将一个复杂对象的构建与它的表示分离, 使得同样的构建过程可以创建不同的表示.<br/>3、工厂模式(factory method pattern): 定义了一个创建对象的接口, 但由子类决定要实例化的类是哪一个. 工厂方法让类把实例化推迟到子类.<br/>4、原型模式(prototype pattern): 当创建给定类的实例过程很昂贵或很复杂时, 就使用原形模式.<br/>5、单例了模式(Singleton pattern): 确保一个类只有一个实例, 并提供全局访问点.<br/>6、多例模式(Multition pattern): 在一个解决方案中结合两个或多个模式, 以解决一般或重复发生的问题.<br/><br/><span style=\"font-size: 14px; color: rgb(255, 0, 0);\">二、结构型模式</span></span></p><p style=\"line-height: 2em;\"><span style=\"font-size: 14px;\">1、适配器模式(Adapter pattern): 将一个类的接口, 转换成客户期望的另一个接口. 适配器让原本接口不兼容的类可以合作无间. 对象适配器使用组合, 类适配器使用多重继承.<br/>2、桥接模式(Bridge pattern): 使用桥接模式通过将实现和抽象放在两个不同的类层次中而使它们可以独立改变.<br/>3、组合模式(composite pattern): 允许你将对象组合成树形结构来表现&quot;整体/部分&quot;层次结构. 组合能让客户以一致的方式处理个别对象以及对象组合.<br/>4、装饰者模式(decorator pattern): 动态地将责任附加到对象上, 若要扩展功能, 装饰者提供了比继承更有弹性的替代方案.<br/>5、外观模式(facade pattern): 提供了一个统一的接口, 用来访问子系统中的一群接口. 外观定义了一个高层接口, 让子系统更容易使用.<br/>6、亨元模式(Flyweight Pattern): 如想让某个类的一个实例能用来提供许多&quot;虚拟实例&quot;, 就使用蝇量模式.<br/>7、代理模式(Proxy pattern): 为另一个对象提供一个替身或占位符以控制对这个对象的访问.<br/><br/><span style=\"font-size: 14px; color: rgb(255, 0, 0);\">三、行为型模式</span></span></p><p style=\"line-height: 2em;\"><span style=\"font-size: 14px;\">1、责任链模式(Chain of responsibility pattern): 通过责任链模式, 你可以为某个请求创建一个对象链. 每个对象依序检查此请求并对其进行处理或者将它传给链中的下一个对象.<br/>2、命令模式(Command pattern): 将&quot;请求&quot;封闭成对象, 以便使用不同的请求,队列或者日志来参数化其他对象. 命令模式也支持可撤销的操作.<br/>3、解释器模式(Interpreter pattern): 使用解释器模式为语言创建解释器.<br/>4、迭代器模式(iterator pattern): 提供一种方法顺序访问一个聚合对象中的各个元素, 而又不暴露其内部的表示.<br/>5、中介者模式(Mediator pattern) : 使用中介者模式来集中相关对象之间复杂的沟通和控制方式.<br/>6、备忘录模式(Memento pattern): 当你需要让对象返回之前的状态时(例如, 你的用户请求&quot;撤销&quot;), 你使用备忘录模式.<br/>7、观察者模式(observer pattern): 在对象之间定义一对多的依赖, 这样一来, 当一个对象改变状态, 依赖它的对象都会收到通知, 并自动更新.<br/>8、状态模式(State pattern): 允许对象在内部状态改变时改变它的行为, 对象看起来好象改了它的类.<br/>9、策略模式(strategy pattern): 定义了算法族, 分别封闭起来, 让它们之间可以互相替换, 此模式让算法的变化独立于使用算法的客户.<br/>10、模板方法模式(Template pattern): 在一个方法中定义一个算法的骨架, 而将一些步骤延迟到子类中. 模板方法使得子类可以在不改变算法结构的情况下, 重新定义算法中的某些步骤.<br/>11、访问者模式(visitor pattern): 当你想要为一个对象的组合增加新的能力, 且封装并不重要时, 就使用访问者模式.<br/><br/>&nbsp;<br/>--------------------------------------------------------------------------------------------------<br/><br/><span style=\"font-size: 14px; color: rgb(255, 0, 0);\">七大设计原则：</span></span></p><p style=\"line-height: 2em;\"><span style=\"font-size: 14px;\">1、单一职责原则【SINGLE RESPONSIBILITY PRINCIPLE】：一个类负责一项职责.<br/>2、里氏替换原则【LISKOV SUBSTITUTION PRINCIPLE】：继承与派生的规则.<br/>3、依赖倒置原则【DEPENDENCE INVERSION PRINCIPLE】：高层模块不应该依赖低层模块，二者都应该依赖其抽象；抽象不应该依赖细节；细节应该依赖抽象。即针对接口编程，不要针对实现编程.<br/>4、接口隔离原则【INTERFACE SEGREGATION PRINCIPLE】：建立单一接口，不要建立庞大臃肿的接口，尽量细化接口，接口中的方法尽量少.<br/>5、迪米特法则【LOW OF DEMETER】：低耦合，高内聚.<br/>6、开闭原则【OPEN CLOSE PRINCIPLE】：一个软件实体如类、模块和函数应该对扩展开放，对修改关闭.<br/>7、组合/聚合复用原则【Composition/Aggregation Reuse Principle(CARP) 】：尽量使用组合和聚合少使用继承的关系来达到复用的原则.</span></p><p style=\"line-height: 2em;\"><span style=\"font-size: 14px;\"><br/></span></p>','2015-10-26 15:41:08','2015-10-26 15:41:08','55631ee26ec09df591a730ed','1','Java中的24种设计模式与7大原则',1,'',1),('563ac1e2a733f20ce3784296','大数据量查询优化——数据库设计、SQL语句、JAVA编码','<p style=\"line-height: 2em;\"><span style=\"color: rgb(255, 0, 0); font-size: 16px;\"><strong><span style=\"color: rgb(255, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none;\">数据库设计方面</span>：</strong></span></p><p style=\"line-height: 2em; text-indent: 2em; margin-top: 5px; text-align: justify;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">1、对查询进行优化，应尽量避免全表扫描，首先应考虑在&nbsp;where&nbsp;及&nbsp;order&nbsp;by&nbsp;涉及的列上建立索引。</span></p><p style=\"line-height: 2em; text-indent: 2em; margin-top: 5px; text-align: justify;\"><span style=\"font-size: 14px;\">2、应尽量避免在 where 子句中对字段进行 null 值判断，否则将导致引擎放弃使用索引而进行全表扫描。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如： select id from t where num is null <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以在num上设置默认值0，确保表中num列没有null值，然后这样查询： select id from t where num=0 </span></p><p style=\"line-height: 2em; text-indent: 2em; margin-top: 5px; text-align: justify;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">3、并不是所有索引对查询都有效，SQL是根据表中数据来进行查询优化的，当索引列有大量数据重复时,查询可能不会去利用索引，如一表中有字段sex，male、female几乎各一半，</span></p><p style=\"line-height: 2em; text-indent: 2em; margin-top: 5px; text-align: justify;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp; 那么即使在sex上建了索引也对查询效率起不了作用。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">4、索引并不是越多越好，索引固然可以提高相应的&nbsp;select&nbsp;的效率，但同时也降低了&nbsp;insert&nbsp;及&nbsp;update&nbsp;的效率，因为&nbsp;insert&nbsp;或&nbsp;update&nbsp;时有可能会重建索引，所以怎样建索引需要慎重</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp; 考虑，视具体情况而定。一个表的索引数最好不要超过6个，若太多则应考虑一些不常使用到的列上建的索引是否有必要。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">5、应尽可能的避免更新索引数据列，因为索引数据列的顺序就是表记录的物理存储顺序，一旦该列值改变将导致整个表记录的顺序的调整，会耗费相当大的资源。若应用系统需要频</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp; 繁更新索引数据列，那么需要考虑是否应将该索引建为索引。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">6、尽量使用数字型字段，若只含数值信息的字段尽量不要设计为字符型，这会降低查询和连接的性能，并会增加存储开销。这是因为引擎在处理查询和连接时会逐个比较字符串中每</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp; 一个字符，而对于数字型而言只需要比较一次就够了。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 12px;\">7、</span>尽可能的使用&nbsp;varchar/nvarchar&nbsp;代替&nbsp;char/nchar&nbsp;，因为首先变长字段存储空间小，可以节省存储空间，其次对于查询来说，在一个相对较小的字段内搜索效率显然要高些。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">8、避免频繁创建和删除临时表，以减少系统表资源的消耗。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">9、临时表并不是不可使用，适当地使用它们可以使某些例程更有效，例如，当需要重复引用大型表或常用表中的某个数据集时。但是，对于一次性事件，最好使用导出表。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">10、在新建临时表时，如果一次性插入数据量很大，那么可以使用&nbsp;select&nbsp;into&nbsp;代替&nbsp;create&nbsp;table，避免造成大量&nbsp;log&nbsp;，以提高速度；如果数据量不大，为了缓和系统表的资源，应先&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create&nbsp;table，然后insert。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">11、如果使用到了临时表，在存储过程的最后务必将所有的临时表显式删除，先&nbsp;truncate&nbsp;table&nbsp;，然后&nbsp;drop&nbsp;table&nbsp;，这样可以避免系统表的较长时间锁定。</span></p><p><br/></p><p><br/></p><p style=\"line-height: 2em;\"><span style=\"color: rgb(255, 0, 0); font-size: 16px;\"><span style=\"color: rgb(255, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none;\">SQL语句方面</span>：</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">1、应尽量避免在&nbsp;where&nbsp;子句中使用!=或&lt;&gt;操作符，否则将引擎放弃使用索引而进行全表扫描。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"font-size: 14px;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none;\">2、应尽量避免在&nbsp;where&nbsp;子句中使用&nbsp;or&nbsp;来连接条件，否则将导致引擎放弃使用索引而进行全表扫描</span><br/><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num=10&nbsp;or&nbsp;num=20 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以这样查询：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num=10&nbsp;union&nbsp;all&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num=20</span></span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">3、in&nbsp;和&nbsp;not&nbsp;in&nbsp;也要慎用，否则会导致全表扫描。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num&nbsp;in(1,2,3) <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对于连续的数值，能用&nbsp;between&nbsp;就不要用&nbsp;in&nbsp;了：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num&nbsp;between&nbsp;1&nbsp;and&nbsp;3</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">4、下面的查询也将导致全表扫描：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;name&nbsp;like&nbsp;‘%abc%’</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">5、如果在&nbsp;where&nbsp;子句中使用参数，也会导致全表扫描。因为SQL只有在运行时才会解析局部变量，但优化程序不能将访问计划的选择推迟到运行时；它必须在编译时进行选择。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp; 然而，如果在编译时建立访问计划，变量的值还是未知的，因而无法作为索引选择的输入项。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如下面语句将进行全表扫描：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num=@num <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以改为强制查询使用索引：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;with(index(索引名))&nbsp;where&nbsp;num=@num</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">6、应尽量避免在&nbsp;where&nbsp;子句中对字段进行表达式操作，这将导致引擎放弃使用索引而进行全表扫描。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num/2=100 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 应改为:&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;num=100*2&nbsp; </span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">7、应尽量避免在where子句中对字段进行函数操作，这将导致引擎放弃使用索引而进行全表扫描。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如：&nbsp;select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;substring(name,1,3)=’abc’&nbsp;&nbsp; ——name以abc开头的id <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;datediff(day,createdate,’2005-11-30′)=0&nbsp; ——‘2005-11-30’生成的id <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 应改为：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;name&nbsp;like&nbsp;‘abc%’ <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select&nbsp;id&nbsp;from&nbsp;t&nbsp;where&nbsp;createdate&gt;=’2005-11-30′&nbsp;and&nbsp;createdate&lt;’2005-12-1′&nbsp; </span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">8、不要在&nbsp;where&nbsp;子句中的“=”左边进行函数、算术运算或其他表达式运算，否则系统将可能无法正确使用索引。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">9、不要写一些没有意义的查询，如需要生成一个空表结构：&nbsp;select&nbsp;col1,col2&nbsp;into&nbsp;#t&nbsp;from&nbsp;t&nbsp;where&nbsp;1=0&nbsp;这类代码不会返回任何结果集，但是会消耗系统资源的，</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp; 应改成这样：&nbsp;create&nbsp;table&nbsp;#t(„)</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">10、很多时候用&nbsp;exists&nbsp;代替&nbsp;in&nbsp;是一个好的选择：&nbsp;select&nbsp;num&nbsp;from&nbsp;a&nbsp;where&nbsp;num&nbsp;in(select&nbsp;num&nbsp;from&nbsp;b) <br/></span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用下面的语句替换：&nbsp;select&nbsp;num&nbsp;from&nbsp;a&nbsp;where&nbsp;exists(select&nbsp;1&nbsp;from&nbsp;b&nbsp;where&nbsp;num=a.num)&nbsp; </span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">11、任何地方都不要使用&nbsp;select&nbsp;*&nbsp;from&nbsp;t&nbsp;，用具体的字段列表代替“*”，不要返回用不到的任何字段。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">12、尽量避免使用游标，因为游标的效率较差，如果游标操作的数据超过1万行，那么就应该考虑改写。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">13、尽量避免向客户端返回大数据量，若数据量过大，应该考虑相应需求是否合理。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">14、尽量避免大事务操作，提高系统并发能力。</span></p><p><br/></p><p style=\"line-height: 2em;\"><span style=\"font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; color: rgb(255, 0, 0); font-size: 16px;\"><span style=\"color: rgb(255, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none;\">java方面</span>：</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">1、尽可能的少造对象。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">2、合理摆正系统设计的位置。大量数据操作，和少量数据操作一定是分开的。大量的数据操作，肯定不是ORM框架搞定的。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">3、使用jDBC链接数据库操作数据。 </span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">4、控制好内存，让数据流起来，而不是全部读到内存再处理，而是边读取边处理。</span></p><p style=\"line-height: 2em; text-indent: 2em;\"><span style=\"color: rgb(54, 46, 43); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; display: inline ! important; float: none; font-size: 14px;\">5、合理利用内存，有的数据要缓存<br/><br/><br/></span></p>','2015-11-05 10:41:38','2015-11-05 10:41:38','55631ee26ec09df591a730ed','1','在一个千万级的数据库查寻中，如何提高查询效率？列出在数据库设计、SQL语句、java等层面的解决方案。',1,'',1),('56945db93664f20c01ddc1f8','excel读取 工具类','<p><br/></p><p><span style=\"font-size: 12px; color: rgb(0, 176, 80);\">JAVA源码如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 12px;\">package cn.yongche.utils;<br/><br/>import java.io.File;<br/>import java.io.FileInputStream;<br/>import java.io.IOException;<br/>import java.io.InputStream;<br/>import java.util.ArrayList;<br/>import java.util.List;<br/>import org.apache.poi.hssf.usermodel.HSSFCell;<br/>import org.apache.poi.hssf.usermodel.HSSFWorkbook;<br/>import org.apache.poi.ss.usermodel.Cell;<br/>import org.apache.poi.ss.usermodel.Row;<br/>import org.apache.poi.ss.usermodel.Sheet;<br/>import org.apache.poi.ss.usermodel.Workbook;<br/>import org.apache.poi.xssf.usermodel.XSSFWorkbook;<br/><br/>/**<br/> * excel读取 工具类<br/> * <br/> * @jar包<br/> * &nbsp; &nbsp; &nbsp;该类使用到了以下jar：<br/> * &nbsp; &nbsp; &nbsp;1、poi-ooxml-3.9.jar<br/> * &nbsp; &nbsp; &nbsp;2、poi-3.9.jar<br/> */<br/>public class ImportExecl {<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * main测试<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void main(String[] args) throws Exception {<br/> &nbsp; &nbsp; &nbsp; &nbsp;ImportExecl poi = new ImportExecl();<br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;List&lt;String&gt;&gt; list = poi.read(&quot;E:/批量导入客户模板.xlsx&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (list != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; list.size(); i++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;String&gt; cellList = list.get(i);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int j = 0; j &lt; cellList.size(); j++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.print(&quot; &nbsp; &nbsp;&quot; + cellList.get(j));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;//总行数<br/> &nbsp; &nbsp;private int totalRows = 0;<br/><br/> &nbsp; &nbsp;//总列数<br/> &nbsp; &nbsp;private int totalCells = 0;<br/><br/> &nbsp; &nbsp;//错误信息<br/> &nbsp; &nbsp;private String errorInfo;<br/><br/> &nbsp; &nbsp;//构造方法<br/> &nbsp; &nbsp;public ImportExecl() {<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 得到总行数<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public int getTotalRows() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return totalRows;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 得到总列数<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public int getTotalCells() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return totalCells;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 得到错误信息<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public String getErrorInfo() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return errorInfo;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 验证excel文件<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public boolean validateExcel(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;/** 检查文件名是否为空或者是否是Excel格式的文件 */<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (filePath == null || !(CheckExcelUtil.isExcel2003(filePath) || CheckExcelUtil.isExcel2007(filePath))) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorInfo = &quot;文件名不是excel格式&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;/** 检查文件是否存在 */<br/> &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (file == null || !file.exists()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorInfo = &quot;文件不存在&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 根据文件路径读取excel文件<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public List&lt;List&lt;String&gt;&gt; read(String filePath) throws IOException {<br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;List&lt;String&gt;&gt; dataLst = new ArrayList&lt;List&lt;String&gt;&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;InputStream is = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/** 验证文件是否合法 */<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!validateExcel(filePath)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(errorInfo);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/** 判断文件的类型，是2003还是2007 */<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boolean isExcel2003 = true;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (CheckExcelUtil.isExcel2007(filePath)) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;isExcel2003 = false;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/** 调用本类提供的根据流读取的方法 */<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(filePath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is = new FileInputStream(file);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dataLst = read(is, isExcel2003);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (Exception ex) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ex.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;} finally {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (is != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return dataLst;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 根据流读取Excel文件<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @param inputStream 文件输入流<br/> &nbsp; &nbsp; * @param isExcel2003 标识是否2003的excel。<br/> * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;true：是2003的excel，false：是2007的excel<br/> &nbsp; &nbsp; * @return<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; * @扩展说明 <br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;如果使用springmvc的MultipartFile接收前端上传的excel文件的话，可以使用MultipartFile的对象，获取上传的文件名称，<br/> &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;然后，可以通过 CheckExcelUtil 类的方法，接收文件名称参数，来判断excel所属的版本。最后再调用此方法来读取excel数据。<br/> &nbsp; &nbsp; * <br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public List&lt;List&lt;String&gt;&gt; read(InputStream inputStream, boolean isExcel2003) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;List&lt;String&gt;&gt; dataLst = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/** 根据版本选择创建Workbook的方式 */<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Workbook wb = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (isExcel2003) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wb = new HSSFWorkbook(inputStream);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wb = new XSSFWorkbook(inputStream);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dataLst = read(wb);<br/> &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return dataLst;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 读取数据<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;private List&lt;List&lt;String&gt;&gt; read(Workbook wb) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;List&lt;List&lt;String&gt;&gt; dataLst = new ArrayList&lt;List&lt;String&gt;&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp;//得到第一个shell<br/> &nbsp; &nbsp; &nbsp; &nbsp;Sheet sheet = wb.getSheetAt(0);<br/> &nbsp; &nbsp; &nbsp; &nbsp;//得到Excel的行数<br/> &nbsp; &nbsp; &nbsp; &nbsp;this.totalRows = sheet.getPhysicalNumberOfRows();<br/> &nbsp; &nbsp; &nbsp; &nbsp;//得到Excel的列数<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (this.totalRows &gt;= 1 &amp;&amp; sheet.getRow(0) != null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//循环Excel的行<br/> &nbsp; &nbsp; &nbsp; &nbsp;for (int r = 0; r &lt; this.totalRows; r++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Row row = sheet.getRow(r);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (row == null) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;continue;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;String&gt; rowLst = new ArrayList&lt;String&gt;();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//循环Excel的列<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int c = 0; c &lt; this.getTotalCells(); c++) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Cell cell = row.getCell(c);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String cellValue = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (null != cell) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 以下是判断数据的类型<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;switch (cell.getCellType()) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case HSSFCell.CELL_TYPE_NUMERIC: // 数字<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cellValue = cell.getNumericCellValue() + &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case HSSFCell.CELL_TYPE_STRING: // 字符串<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cellValue = cell.getStringCellValue();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cellValue = cell.getBooleanCellValue() + &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case HSSFCell.CELL_TYPE_FORMULA: // 公式<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cellValue = cell.getCellFormula() + &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case HSSFCell.CELL_TYPE_BLANK: // 空值<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cellValue = &quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case HSSFCell.CELL_TYPE_ERROR: // 故障<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cellValue = &quot;非法字符&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cellValue = &quot;未知类型&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rowLst.add(cellValue);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//保存第r行的第c列<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dataLst.add(rowLst);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return dataLst;<br/> &nbsp; &nbsp;}<br/><br/>}<br/><br/>class CheckExcelUtil {<br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 检查是否是2003的excel，若是，则返回true<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isExcel2003(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return filePath.matches(&quot;^.+\\\\.(?i)(xls)$&quot;);<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * 检查是否是2007的excel，若是，则返回true<br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static boolean isExcel2007(String filePath) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;return filePath.matches(&quot;^.+\\\\.(?i)(xlsx)$&quot;);<br/> &nbsp; &nbsp;}<br/>}<br/></span></code></pre><p><br/></p>','2016-01-12 09:58:17','2016-01-12 09:58:17','55631ee26ec09df591a730ed','1','读取Excel工具类，包含流读取、文件读取。',1,'',1),('56a57acb3664f20c02ddc1f8','对电脑屏幕进行拍照(屏幕截图),保存为图片---工具类','<p><span style=\"font-size: 12px; color: rgb(0, 176, 80);\">代码如下：</span></p><pre class=\"brush:java;toolbar:false\"><code><span style=\"font-size: 12px;\">package com.zb.onlinesource;<br/>import java.awt.Dimension;<br/>import java.awt.Rectangle;<br/>import java.awt.Robot;<br/>import java.awt.Toolkit;<br/>import java.awt.image.BufferedImage;<br/>import java.io.File;<br/><br/>import javax.imageio.ImageIO;<br/><br/>/**<br/> * 对屏幕进行拍照(屏幕截图),保存为图片,格式任意设置,比如 jpg、png、jpeg、gif <br/> * <br/> * 可直接运行main方法测试<br/> * <br/> */<br/>public class ScreenCaptureUtil {<br/><br/> &nbsp; &nbsp;private String fileName; //文件名称<br/> &nbsp; <br/> &nbsp; &nbsp;private String imageFormat; //图像文件的格式<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;private String defaultImageFormat=&quot;png&quot;;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();<br/><br/> &nbsp; &nbsp;/****************************************************************<br/> &nbsp; &nbsp; &nbsp; * 默认的文件前缀为capture，文件格式为PNG格式<br/> &nbsp; &nbsp;****************************************************************/<br/> &nbsp; &nbsp;public ScreenCaptureUtil() {<br/> &nbsp; &nbsp; &nbsp; &nbsp;imageFormat = defaultImageFormat;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp; <br/> &nbsp; &nbsp;/****************************************************************<br/> &nbsp; &nbsp; &nbsp; * 本构造支持JPG和PNG文件的存储<br/> &nbsp; &nbsp;****************************************************************/<br/> &nbsp; &nbsp;public ScreenCaptureUtil(String fileName,String format) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;this.fileName = fileName;<br/> &nbsp; &nbsp; &nbsp; &nbsp;this.imageFormat = format;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/****************************************************************<br/> &nbsp; &nbsp; &nbsp; * 对屏幕进行拍照<br/> &nbsp; &nbsp;****************************************************************/<br/> &nbsp; &nbsp;public void snapShot(){<br/> &nbsp; &nbsp; &nbsp; &nbsp;try{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//拷贝屏幕到一个BufferedImage对象<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(0, 0, (int) dimension.getWidth(), (int) dimension.getHeight()));<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//这里的文件名称，可以自行设置<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String name = fileName + &quot;.&quot; + imageFormat;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File f = new File(name);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.print(&quot;Save File &quot; + name);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//将screenshot对象写入图像文件<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageIO.write(screenshot, imageFormat, f);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.print(&quot; &nbsp;..Finished!\\n&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}catch (Exception ex) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(ex);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;/**<br/> &nbsp; &nbsp; * main测试。第二个参数是图片的格式。可以任意设置，比如 jpg、png、jpeg、gif都可以。 <br/> &nbsp; &nbsp; */<br/> &nbsp; &nbsp;public static void main(String[] a){<br/> &nbsp; &nbsp; &nbsp; &nbsp;ScreenCaptureUtil ScreenCapture = new ScreenCaptureUtil(&quot;E:\\\\Hello111&quot;, &quot;jpg&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;ScreenCapture.snapShot();<br/> &nbsp; &nbsp;}<br/>} <br/></span></code></pre><p><br/></p>','2016-01-25 09:30:51','2016-01-25 09:30:51','5568000980689df542ea01f6','1','对屏幕进行拍照(屏幕截图),保存为图片,格式任意设置,比如 jpg、png、jpeg、gif ',1,'',1),('56a979ad3664f20c03ddc1f8','DateTimePicker：jQuery日期和时间插件','<p><br/></p><p><a href=\"/resources/demoSources/jquery_datetimepicker/index.html\" target=\"_blank\" title=\"DateTimePicker：jQuery日期和时间插件\" style=\"text-decoration: underline; font-size: 14px; color: rgb(227, 108, 9);\"><span style=\"font-size: 14px; color: rgb(227, 108, 9);\">点击在线预览效果</span></a><span style=\"font-size: 14px; color: rgb(227, 108, 9);\"> &nbsp;<span style=\"font-size: 14px; color: rgb(0, 176, 240);\">&nbsp; &nbsp; &nbsp;</span></span><a href=\"/resources/attached/file/DateTimePicker_JQuery日期和时间插件.zip\" target=\"_blank\" title=\"DateTimePicker_JQuery日期和时间插件.zip\" style=\"font-size: 14px; color: rgb(227, 108, 9); text-decoration: underline;\"><span style=\"color: rgb(227, 108, 9);\">点击下载该插件</span></a></p><p><br/></p><p><span style=\"color: rgb(0, 176, 80); font-size: 14px;\">下面是效果截图：</span></p><p><img src=\"/resources/attached/image/201601281453946689808016509.jpg\" title=\"201601281453946689808016509.jpg\" alt=\"201601281453946689808016509.jpg\" width=\"400\" height=\"250\" border=\"0\" vspace=\"0\" style=\"width: 400px; height: 250px;\"/></p><p><br/></p><p><br/></p><p><img src=\"/resources/attached/image/201601281453946779497079327.jpg\" title=\"201601281453946779497079327.jpg\" alt=\"201601281453946779497079327.jpg\" width=\"300\" height=\"300\" border=\"0\" vspace=\"0\" style=\"width: 300px; height: 300px;\"/></p><p><br/></p><p><img src=\"/resources/attached/image/201601281453946863796071791.jpg\" title=\"201601281453946863796071791.jpg\" alt=\"201601281453946863796071791.jpg\" width=\"600\" height=\"350\" border=\"0\" vspace=\"0\" style=\"width: 600px; height: 350px;\"/></p><p><br/></p><p><br/></p><p><img src=\"/resources/attached/image/201601281453946954775020100.jpg\" title=\"201601281453946954775020100.jpg\" alt=\"201601281453946954775020100.jpg\" width=\"100\" height=\"350\" border=\"0\" vspace=\"0\" style=\"width: 100px; height: 350px;\"/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p>','2016-01-28 10:15:09','2016-01-28 10:15:09','5','1','使用此插件非强制性地将 datetimepicker、 datepicker 或 timepicker 下拉列表添加到您的窗体。',1,'',1);

/*Table structure for table `blog_menu` */

DROP TABLE IF EXISTS `blog_menu`;

CREATE TABLE `blog_menu` (
  `id` varchar(24) NOT NULL,
  `name` varchar(20) NOT NULL COMMENT '菜单名称',
  `pid` varchar(24) NOT NULL COMMENT '父级id',
  `link` varchar(100) DEFAULT NULL COMMENT '菜单链接',
  `available` int(1) NOT NULL DEFAULT '1' COMMENT '菜单是否禁用，默认1可用',
  `model` int(1) NOT NULL DEFAULT '1' COMMENT '标识菜单所属模块，1：后台  2：会员个人中心',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `blog_menu` */

insert  into `blog_menu`(`id`,`name`,`pid`,`link`,`available`,`model`) values ('55470914a0875c46bac307db','菜单管理','-1',NULL,1,1),('55470949a0875c46bbc307db','后台菜单','55470914a0875c46bac307db','/menu/toMenuManage?type=1',1,1),('55470962a0875c46bcc307db','会员菜单','55470914a0875c46bac307db','/menu/toMenuManage?type=2',1,1),('55470977a0875c46bdc307db','会员管理','-1',NULL,1,1),('5547098ca0875c46bec307db','会员列表','55470977a0875c46bdc307db','/user/toUserList',1,1),('554709aea0875c46bfc307db','角色管理','-1',NULL,1,1),('554709c2a0875c46c0c307db','角色列表','554709aea0875c46bfc307db','/role/toRoleList',1,1),('554709d4a0875c46c1c307db','权限管理','-1',NULL,1,1),('554709e7a0875c46c2c307db','权限列表','554709d4a0875c46c1c307db','/permission/toPermissionList',1,1),('55470fba21825c46a4c7f7cd','菜单列表','55470914a0875c46bac307db','/menu/toMenuList',1,1),('55496a6ac2765c465e5fea3b','导航管理','-1',NULL,1,1),('55496ac5c2765c465f5fea3b','导航列表','55496a6ac2765c465e5fea3b','/navigation/toNavigationList',1,1),('5549c20ebb725c46ae6545cf','收藏管理','-1',NULL,1,2),('5549c242bb725c46af6545cf','个人资料','-1',NULL,1,2),('5549c25fbb725c46b06545cf','系统消息','-1',NULL,1,2),('5549c273bb725c46b16545cf','问题反馈','-1',NULL,1,2),('5549c4e7bb725c46b26545cf','微信推送','-1',NULL,1,1),('5549c5bcbb725c46b36545cf','推送列表','5549c4e7bb725c46b26545cf','/push/pushListView',1,1),('554c0659f9195c462885b1ee','文章管理','-1',NULL,1,1),('554c069ff9195c462985b1ee','文章列表','554c0659f9195c462885b1ee','/article/articleListView',1,1);

/*Table structure for table `blog_navigation` */

DROP TABLE IF EXISTS `blog_navigation`;

CREATE TABLE `blog_navigation` (
  `id` varchar(24) NOT NULL,
  `name` varchar(50) NOT NULL COMMENT '类型名称',
  `pid` varchar(24) NOT NULL COMMENT '父id',
  `indexNo` int(11) NOT NULL COMMENT '排序',
  `available` int(1) NOT NULL DEFAULT '1' COMMENT '是否可用',
  `link` varchar(100) DEFAULT NULL COMMENT '链接',
  `linkType` int(1) NOT NULL DEFAULT '1' COMMENT '链接类型：1表示查询文章列表  2表示链接到一个view页面',
  `icon` varchar(20) NOT NULL COMMENT '图标',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='导航栏';

/*Data for the table `blog_navigation` */

insert  into `blog_navigation`(`id`,`name`,`pid`,`indexNo`,`available`,`link`,`linkType`,`icon`) values ('1','首页','0',0,1,'/index/index',2,'home'),('10','权限控制','3',0,1,NULL,1,'sliders'),('11','服务器集群','3',2,1,NULL,1,'server'),('12','单点登录','3',3,1,NULL,1,'key'),('2','励志文章','0',1,1,NULL,1,'book'),('3','技术教程','0',2,1,NULL,1,'file-text-o'),('4','资源下载','0',3,1,'/article/articleDetail/5567c9a36ec09df598a730ed',2,'download'),('5','前端','0',5,1,NULL,1,'html5'),('55631ee26ec09df591a730ed','JAVA','3',0,1,NULL,1,'coffee'),('556322b76ec09df593a730ed','Spring','3',0,1,NULL,1,'pagelines'),('5566e8f36ec09df596a730ed','数据库','3',0,1,NULL,1,'database'),('5568000980689df542ea01f6','工具类','0',7,1,NULL,1,'wrench'),('55dbcbe592eaf20c53d24e8b','Linux','3',0,1,NULL,1,'linux'),('55fa57caea01f20c425bb66c','在线工具','0',4,0,'/online/view',2,'cogs'),('55ffa18a9ff1e8de3d6cc348','常用资源','0',9,1,NULL,2,'recycle'),('55ffa1ba9ff1e8de3e6cc348','前端','55ffa18a9ff1e8de3d6cc348',0,1,NULL,1,'html5'),('5601125b4f88f20c9320e95f','网站收藏','0',10,0,'/favorite',2,'star'),('6','特效插件','0',6,0,NULL,1,'thumb-tack'),('7','网站简介','0',0,0,NULL,2,'file-word-o'),('8','交流园地','0',0,0,NULL,2,'child'),('9','关于作者','0',0,0,NULL,2,'user');

/*Table structure for table `blog_permission` */

DROP TABLE IF EXISTS `blog_permission`;

CREATE TABLE `blog_permission` (
  `id` varchar(24) NOT NULL,
  `name` varchar(20) NOT NULL COMMENT '权限名称',
  `code` varchar(50) NOT NULL COMMENT '权限代码',
  `description` varchar(50) DEFAULT NULL COMMENT '描述',
  `parentId` varchar(24) DEFAULT NULL COMMENT '父id',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限表';

/*Data for the table `blog_permission` */

insert  into `blog_permission`(`id`,`name`,`code`,`description`,`parentId`) values ('55408190650d5c4628e16d3c','系统管理','system:mgt',NULL,'0'),('554081ad650d5c4629e16d3c','会员管理','user:mgt',NULL,'55408190650d5c4628e16d3c'),('554081be650d5c462ae16d3c','角色管理','role:mgt',NULL,'55408190650d5c4628e16d3c'),('554081d9650d5c462be16d3c','权限管理','permission:mgt',NULL,'55408190650d5c4628e16d3c'),('554081ff650d5c462ce16d3c','文章管理','article:mgt',NULL,'55408190650d5c4628e16d3c'),('5540822d650d5c462de16d3c','留言管理','message:mgt',NULL,'55408190650d5c4628e16d3c'),('5540823c650d5c462ee16d3c','推送管理','push:mgt',NULL,'55408190650d5c4628e16d3c'),('55408251650d5c462fe16d3c','资源管理','source:mgt',NULL,'55408190650d5c4628e16d3c'),('55408270650d5c4630e16d3c','下载管理','download:mgt',NULL,'55408190650d5c4628e16d3c'),('5540828e650d5c4631e16d3c','统计管理','statistical:mgt',NULL,'55408190650d5c4628e16d3c'),('554082fc650d5c463ce16d3c','会员列表','user:list',NULL,'554081ad650d5c4629e16d3c'),('5540831f650d5c463de16d3c','会员编辑','user:edit',NULL,'554081ad650d5c4629e16d3c'),('55408333650d5c463ee16d3c','会员信息','user:view',NULL,'554081ad650d5c4629e16d3c'),('5540836a650d5c463fe16d3c','角色编辑','role:edit',NULL,'554081be650d5c462ae16d3c'),('5540837e650d5c4640e16d3c','角色列表','role:list',NULL,'554081be650d5c462ae16d3c'),('5540839d650d5c4641e16d3c','权限列表','permission:list',NULL,'554081d9650d5c462be16d3c'),('554083b0650d5c4642e16d3c','权限编辑','permission:edit',NULL,'554081d9650d5c462be16d3c'),('554083c5650d5c4643e16d3c','权限信息','permission:view',NULL,'554081d9650d5c462be16d3c'),('554083d1650d5c4644e16d3c','权限添加','permission:add',NULL,'554081d9650d5c462be16d3c'),('5540881d06555c46e638db27','文章列表','article:list',NULL,'554081ff650d5c462ce16d3c'),('5540882f06555c46e738db27','文章信息','article:view',NULL,'554081ff650d5c462ce16d3c'),('5540884606555c46e838db27','文章删除','article:delete',NULL,'554081ff650d5c462ce16d3c'),('5540885606555c46e938db27','文章添加','article:add',NULL,'554081ff650d5c462ce16d3c'),('55408a9b3c265c4639493265','菜单管理','menu:mgt',NULL,'55408190650d5c4628e16d3c'),('55408aab3c265c463a493265','菜单列表','menu:list',NULL,'55408a9b3c265c4639493265'),('55408afe3c265c463b493265','菜单添加','menu:add',NULL,'55408a9b3c265c4639493265'),('55408b0e3c265c463c493265','菜单编辑','menu:edit',NULL,'55408a9b3c265c4639493265'),('5541c64dce3a5c468ed8e1cd','个人中心','center:mgt',NULL,'0'),('5549739dfa845c46c477d40d','导航管理','navigation:mgt',NULL,'55408190650d5c4628e16d3c'),('554973adfa845c46c577d40d','导航列表','navigation:list',NULL,'5549739dfa845c46c477d40d'),('5549784f76125c468f2f238b','导航编辑','navigation:edit',NULL,'5549739dfa845c46c477d40d'),('5549a45a7f915c46c416b7b0','新增导航','navigation:add',NULL,'5549739dfa845c46c477d40d'),('5549c7c9f9115c464fd27023','推送列表','wechat:push:list',NULL,'5540823c650d5c462ee16d3c'),('554c20ff65d25c4619f3a882','文章编辑','article:edit',NULL,'554081ff650d5c462ce16d3c');

/*Table structure for table `blog_role` */

DROP TABLE IF EXISTS `blog_role`;

CREATE TABLE `blog_role` (
  `id` varchar(24) NOT NULL,
  `name` varchar(20) NOT NULL,
  `description` varchar(50) DEFAULT NULL COMMENT '描述',
  `status` int(1) DEFAULT NULL,
  `updateTime` datetime NOT NULL,
  `createTime` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色表';

/*Data for the table `blog_role` */

insert  into `blog_role`(`id`,`name`,`description`,`status`,`updateTime`,`createTime`) values ('1','user','会员',1,'2015-03-14 01:18:40','2015-03-14 01:18:42'),('2','admin','管理员',1,'2015-03-14 01:19:05','2015-03-14 01:19:07');

/*Table structure for table `blog_role_permission` */

DROP TABLE IF EXISTS `blog_role_permission`;

CREATE TABLE `blog_role_permission` (
  `id` varchar(24) NOT NULL,
  `roleId` varchar(24) NOT NULL,
  `permissionId` varchar(24) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色权限表';

/*Data for the table `blog_role_permission` */

insert  into `blog_role_permission`(`id`,`roleId`,`permissionId`) values ('55408b513c265c4658493265','3','55408190650d5c4628e16d3c'),('55408b513c265c4659493265','3','554081ad650d5c4629e16d3c'),('55408b513c265c465a493265','3','554082fc650d5c463ce16d3c'),('5541d4665acc5c46c3694039','1','55408190650d5c4628e16d3c'),('5541d4665acc5c46c4694039','1','554081ff650d5c462ce16d3c'),('5541d4665acc5c46c5694039','1','5540881d06555c46e638db27'),('5541d4665acc5c46c6694039','1','5540882f06555c46e738db27'),('5541d4665acc5c46c7694039','1','5540822d650d5c462de16d3c'),('5541d4665acc5c46c8694039','1','55408270650d5c4630e16d3c'),('5541d4665acc5c46c9694039','1','55408a9b3c265c4639493265'),('5541d4665acc5c46ca694039','1','55408aab3c265c463a493265'),('5541d4665acc5c46cb694039','1','5541c64dce3a5c468ed8e1cd'),('554c210c65d25c461af3a882','2','55408190650d5c4628e16d3c'),('554c210c65d25c461bf3a882','2','554081ad650d5c4629e16d3c'),('554c210c65d25c461cf3a882','2','554082fc650d5c463ce16d3c'),('554c210c65d25c461df3a882','2','5540831f650d5c463de16d3c'),('554c210c65d25c461ef3a882','2','55408333650d5c463ee16d3c'),('554c210c65d25c461ff3a882','2','554081be650d5c462ae16d3c'),('554c210c65d25c4620f3a882','2','5540836a650d5c463fe16d3c'),('554c210c65d25c4621f3a882','2','5540837e650d5c4640e16d3c'),('554c210c65d25c4622f3a882','2','554081d9650d5c462be16d3c'),('554c210c65d25c4623f3a882','2','5540839d650d5c4641e16d3c'),('554c210c65d25c4624f3a882','2','554083b0650d5c4642e16d3c'),('554c210c65d25c4625f3a882','2','554083c5650d5c4643e16d3c'),('554c210c65d25c4626f3a882','2','554083d1650d5c4644e16d3c'),('554c210c65d25c4627f3a882','2','554081ff650d5c462ce16d3c'),('554c210c65d25c4628f3a882','2','5540881d06555c46e638db27'),('554c210c65d25c4629f3a882','2','5540882f06555c46e738db27'),('554c210c65d25c462af3a882','2','5540884606555c46e838db27'),('554c210c65d25c462bf3a882','2','5540885606555c46e938db27'),('554c210c65d25c462cf3a882','2','554c20ff65d25c4619f3a882'),('554c210c65d25c462df3a882','2','5540822d650d5c462de16d3c'),('554c210c65d25c462ef3a882','2','5540823c650d5c462ee16d3c'),('554c210c65d25c462ff3a882','2','5549c7c9f9115c464fd27023'),('554c210c65d25c4630f3a882','2','55408251650d5c462fe16d3c'),('554c210c65d25c4631f3a882','2','55408270650d5c4630e16d3c'),('554c210c65d25c4632f3a882','2','5540828e650d5c4631e16d3c'),('554c210d65d25c4633f3a882','2','55408a9b3c265c4639493265'),('554c210d65d25c4634f3a882','2','55408aab3c265c463a493265'),('554c210d65d25c4635f3a882','2','55408afe3c265c463b493265'),('554c210d65d25c4636f3a882','2','55408b0e3c265c463c493265'),('554c210d65d25c4637f3a882','2','5549739dfa845c46c477d40d'),('554c210d65d25c4638f3a882','2','554973adfa845c46c577d40d'),('554c210d65d25c4639f3a882','2','5549784f76125c468f2f238b'),('554c210d65d25c463af3a882','2','5549a45a7f915c46c416b7b0');

/*Table structure for table `blog_user` */

DROP TABLE IF EXISTS `blog_user`;

CREATE TABLE `blog_user` (
  `id` varchar(24) NOT NULL COMMENT '主键',
  `userName` varchar(20) NOT NULL COMMENT '名称',
  `password` varchar(50) NOT NULL,
  `email` varchar(50) DEFAULT NULL,
  `realName` varchar(20) DEFAULT NULL COMMENT '真实姓名',
  `phone` varchar(11) DEFAULT NULL,
  `status` int(1) NOT NULL COMMENT '用户状态，1：正常  2：锁定   3:删除',
  `updateTime` datetime NOT NULL,
  `createTime` datetime NOT NULL,
  `openId` varchar(50) DEFAULT NULL COMMENT '微信openid',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';

/*Data for the table `blog_user` */

insert  into `blog_user`(`id`,`userName`,`password`,`email`,`realName`,`phone`,`status`,`updateTime`,`createTime`,`openId`) values ('1','zhoubang','56e435efef6e758467ac0acd2fb4391f','842324724@qq.com','周棒','15901718151',1,'2015-04-29 14:59:37','2015-03-14 01:17:39',NULL),('2','zhangsan','e10adc3949ba59abbe56e057f20f883e','','张三','15901718152',1,'2015-04-29 15:37:44','2015-03-14 01:18:09',NULL),('3','lisi','e10adc3949ba59abbe56e057f20f883e','','李四','15901718155',1,'2015-04-30 11:19:27','2015-03-14 01:18:26',NULL),('555d5ac573dc9df5a477610e','luqiaolong','c3fc854d1e06451307926f7a43873ec9','136073758@qq.com','luqiaolong','12312',1,'2015-05-21 12:10:46','2015-05-21 12:10:46',NULL),('559601a9de9a9df5705ef1ec','ljc','ef4841951b810fc0a930b89b48a9ff25','631114161@qq.com','','',1,'2015-07-03 11:29:45','2015-07-03 11:29:45',NULL),('55a028b1930d9df54ec2f2d1','天尊','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2016-01-28 12:14:38','2015-07-11 04:18:57','BA0DB23E90154F385568611D0951EFA7'),('55a02cbf34949df5f26db373','0.0','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2016-01-28 12:14:20','2015-07-11 04:36:15','8E59BCA491CC78EF5E342EC7E876E58C'),('55a0c25b34949df5f46db373','贞子一号','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-07-11 15:14:36','2015-07-11 15:14:36','A99EE69F7597F75015126F6947663A39'),('55d6ad86d701f20cb5729b35','hhll','276a2cd4f9a70899eca50564bd6b2abc','604840505@qq.com','郝雄超','15324000856',1,'2015-08-21 12:48:06','2015-08-21 12:48:06',NULL),('55dab65b3fa2f20ce4d29f97','zhoubang85','4c70635423dcbc04b8f7dc717505c304','zhoubang85@163.com','','',1,'2015-08-24 14:14:51','2015-08-24 14:14:51',NULL),('55db27f03fa2f20ce6d29f97','admin','21232f297a57a5a743894a0e4a801fc3','admin@a.com','2b','13800138000',1,'2015-08-24 22:19:28','2015-08-24 22:19:28',NULL),('55ee7486ebd3f20cc9f07f46','JONE','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-09-08 13:39:18','2015-09-08 13:39:18','A9643E8900ADDFB490795F8607178FA2'),('55ee75a4ebd3f20ccbf07f46','123456','e10adc3949ba59abbe56e057f20f883e','123123','123','1231',1,'2015-09-08 13:44:05','2015-09-08 13:44:05',NULL),('55eed801ea01f20c3e5bb66c','Colin小二爬','a4c71f9f48ca526ef270ff75790f7f1a','xiangkanglin@qq.com','','',1,'2015-09-08 20:43:45','2015-09-08 20:43:45',NULL),('55f8ee1cea01f20c405bb66c','青春不过如此','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-09-16 12:20:44','2015-09-16 12:20:44','E622F5B9FC8B27829D8755A7FFA5B99C'),('55fa8b5ba480f20c7b88a3f4','莫云海','a18aecfd37f79a8201f532c4eabb999b','liuyvenfei@qq.com','莫云海','15294784225',1,'2015-09-17 17:43:55','2015-09-17 17:43:55',NULL),('55fec56da20bf20c0bc4747f','Clear','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-09-20 22:40:45','2015-09-20 22:40:45','03EB6B8C88001350CB972A0DC421578E'),('56150a59f45af20cf995b43a','Zaric','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-10-07 20:04:41','2015-10-07 20:04:41','92EA9735F4823A7F4EC0FC3FF5D21743'),('56177639c9e1f20c9cbc0171','The heart of the sun','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-10-09 16:28:14','2015-10-09 16:09:29','5989E11FEF66D864C02700DFF0D6F40F'),('561b829416eff20ca74693c2','久舞而契','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-10-15 08:42:22','2015-10-12 17:51:16','4DCC110A47EDEE7A645239984AC8B575'),('563ab128a733f20ce1784296','HelloT','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-11-05 09:30:15','2015-11-05 09:30:15','16D8555CE9FA345BE2BAA526FCE791F3'),('567766b5f52cf20c2798671f','旧时光','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2015-12-21 10:40:53','2015-12-21 10:40:53','11615A7DF89D3A99A29F3C586879CAA7'),('567b52a6f52cf20c2998671f','gjldwz','e10adc3949ba59abbe56e057f20f883e','957502@qq.com','王好','15950076438',1,'2015-12-24 10:04:22','2015-12-24 10:04:22',NULL),('567d002df52cf20c2b98671f','123','202cb962ac59075b964b07152d234b70','123','','',1,'2015-12-25 16:37:02','2015-12-25 16:37:02',NULL),('568a15d1158df20cdf846dac','左岸 _/~','e10adc3949ba59abbe56e057f20f883e','',NULL,'',1,'2016-01-04 14:55:36','2016-01-04 14:48:49','D0C6A869C92A31D93B2ACB21112232AA'),('568bf090158df20ce3846dac','cql159357','36e1a5072c78359066ed7715f5ff3da8','123123@qq.com','','',1,'2016-01-06 00:34:24','2016-01-06 00:34:24',NULL),('568f1c033664f20cffdcc1f8','冰小猪','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2016-01-08 10:16:35','2016-01-08 10:16:35','DD84D70643EE1E6D98A91EE23F2962B6'),('56905ef80bebf20c6915976a','jialiuyang','214871e7f7487087c593be4b2f77f267','4951200212qq.com','','1',1,'2016-01-09 09:14:32','2016-01-09 09:14:32',NULL),('56a08cc10bebf20c6b15976a','Pan.','e10adc3949ba59abbe56e057f20f883e',NULL,NULL,NULL,1,'2016-01-21 15:46:09','2016-01-21 15:46:09','67583B0CF40C250758242D5215F2DADB'),('56c17d9e0bebf20c6d15976a','saq1314520','34acf66130267b5665b2b73e37f30265','278730150@qq.com','','',1,'2016-02-15 15:26:22','2016-02-15 15:26:22',NULL);

/*Table structure for table `blog_user_role` */

DROP TABLE IF EXISTS `blog_user_role`;

CREATE TABLE `blog_user_role` (
  `id` varchar(24) NOT NULL,
  `userId` varchar(24) NOT NULL,
  `roleId` varchar(24) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户角色表';

/*Data for the table `blog_user_role` */

insert  into `blog_user_role`(`id`,`userId`,`roleId`) values ('55408159650d5c4626e16d3c','1','1'),('55408159650d5c4627e16d3c','1','2'),('55408a483c265c4638493265','2','1'),('55419f3e1a105c467e08b67d','3','1'),('555d5ac573dc9df5a577610e','555d5ac573dc9df5a477610e','1'),('559601a9de9a9df5715ef1ec','559601a9de9a9df5705ef1ec','1'),('55a028b1930d9df54fc2f2d1','55a028b1930d9df54ec2f2d1','1'),('55a02cc034949df5f36db373','55a02cbf34949df5f26db373','1'),('55a0c25b34949df5f56db373','55a0c25b34949df5f46db373','1'),('55d6ad86d701f20cb6729b35','55d6ad86d701f20cb5729b35','1'),('55dab65b3fa2f20ce5d29f97','55dab65b3fa2f20ce4d29f97','1'),('55db27f03fa2f20ce7d29f97','55db27f03fa2f20ce6d29f97','1'),('55ee7486ebd3f20ccaf07f46','55ee7486ebd3f20cc9f07f46','1'),('55ee75a5ebd3f20cccf07f46','55ee75a4ebd3f20ccbf07f46','1'),('55eed801ea01f20c3f5bb66c','55eed801ea01f20c3e5bb66c','1'),('55f8ee1dea01f20c415bb66c','55f8ee1cea01f20c405bb66c','1'),('55fa8b5ba480f20c7c88a3f4','55fa8b5ba480f20c7b88a3f4','1'),('55fec56da20bf20c0cc4747f','55fec56da20bf20c0bc4747f','1'),('56150a59f45af20cfa95b43a','56150a59f45af20cf995b43a','1'),('56177639c9e1f20c9dbc0171','56177639c9e1f20c9cbc0171','1'),('561b829416eff20ca84693c2','561b829416eff20ca74693c2','1'),('563ab128a733f20ce2784296','563ab128a733f20ce1784296','1'),('567766b5f52cf20c2898671f','567766b5f52cf20c2798671f','1'),('567b52a6f52cf20c2a98671f','567b52a6f52cf20c2998671f','1'),('567d002ef52cf20c2c98671f','567d002df52cf20c2b98671f','1'),('568a1768158df20ce1846dac','568a15d1158df20cdf846dac','1'),('568a1768158df20ce2846dac','568a15d1158df20cdf846dac','2'),('568bf090158df20ce4846dac','568bf090158df20ce3846dac','1'),('568f1c033664f20c00ddc1f8','568f1c033664f20cffdcc1f8','1'),('56905ef80bebf20c6a15976a','56905ef80bebf20c6915976a','1'),('56a08cc20bebf20c6c15976a','56a08cc10bebf20c6b15976a','1'),('56c17d9e0bebf20c6e15976a','56c17d9e0bebf20c6d15976a','1');

/* Function  structure for function  `getParentNameList` */

/*!50003 DROP FUNCTION IF EXISTS `getParentNameList` */;
DELIMITER $$

/*!50003 CREATE DEFINER=`root`@`%` FUNCTION `getParentNameList`(navigationId VARCHAR(24)) RETURNS varchar(100) CHARSET utf8
BEGIN
    DECLARE sTemp VARCHAR(100);
    DECLARE pidv VARCHAR(24);
    SET sTemp = (SELECT n.name FROM blog_navigation n WHERE n.id = navigationId);
    SET pidv = (SELECT pid FROM blog_navigation WHERE id = navigationId);
    WHILE pidv > 0 DO
    SET sTemp = CONCAT((SELECT n.name FROM blog_navigation n WHERE n.id = pidv),'-',sTemp);
    SELECT pid INTO pidv FROM blog_navigation WHERE id = pidv;
    END WHILE;
    RETURN sTemp;
    END */$$
DELIMITER ;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
